【问题标题】:c3.js How do I read max and min axis values?c3.js 如何读取最大和最小轴值?
【发布时间】:2021-05-20 14:38:39
【问题描述】:

我喜欢 c3 中提供的 y 轴自动缩放功能,但我希望能够检索它选择的最大值和最小值。就我而言,我想要 y 轴上的摄氏刻度和 y2 上的等效华氏刻度。好像

console.log(chart.axis.range());
console.log(chart.axis.max());

应该生成(在控制台日志上)我想要的数字,以便我可以将它们转换为华氏度并生成 y2 刻度。不幸的是,我得到了未定义的值。

{x: undefined, y: undefined, y2: undefined}
x: undefined
y: undefined
y2: undefined
__proto__: Object

如果我之前设置了轴的最大值或最小值,则它们已定义,但我想要自动缩放值。

我不希望使用一种解决方法,即扫描数据的 y 值以获得最大值和最小值,然后计算我自己的不再自动缩放值。

谢谢,

保罗

【问题讨论】:

    标签: javascript c3.js


    【解决方案1】:

    这对我来说是为了获得最小值和最大值:

       // First make sure that they are defined, otherwise
       // they can show up as undefined.
       chart.axis.range({max: {x: 4, y: 5}, min: {x: 2, y: 3}});
    
       var axis = chart.axis;  // Shorthand. reference to axis.
       // display them:
       console.log(
           "    x min: " + axis.min()['x'] +
           "    x max: " + axis.max()['x'] +
           "    y min: " + axis.min()['y'] +
           "    y max: " + axis.max()['y']
       ); 
    

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多