Highcharts - 切换自动缩放

时间:2013-08-11 11:43:24

标签: javascript highcharts

我试图制作一个切换按钮,您可以在其中冻结比例。如果再次单击,则会自动重新计算比例(在highcharts中是默认值)。

如果y-axis = {max:null}符合API参考,那么比例是自动的。但是如果我锁定刻度,我必须以某种方式提取y轴刻度,这样我就可以手动将y轴设置为当前值。当我切换回来时,y轴设置为null。

当设置为null时,是否有提取y轴刻度?我还没能在API中找到任何内容。

这是我的高图对象

chartFactory.getBarChart = function(data, duration){
  //console.log(chartData);
  var chart = $('.chart').highcharts({
    chart: {
      renderTo: 'chartContainer',
      type: 'column',
      height: windowHeight - 220, //Set chartsize depending on size of window
      reflow: true
    },
    title: {
      text: "title"
    },
    subtitle: {
      text: "Source: "
    },
    xAxis: {
      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    },
    yAxis: {
      min: 0,
      max: null,
      title: {
        text: 'Energy (kWh)'
      }
    },
    "tooltip": {},
    plotOptions: {
      column: {
        animation: {
          duration: duration
        },
        stacking: 'normal',
        dataLabels: {
          enabled: true,
          color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
        }
      }
    },
    series: data //Calculated data
  })
  .highcharts(); // return chart
}

1 个答案:

答案 0 :(得分:4)

当然,您可以通过调用chart.highcharts()来提取当前图表设置,它包含将具有有效最小值和最大值的每个轴以及基于使用它的系列设置的数据最小值/最大值。

yAxis [0]如果你只有一个可以工作,但在Axis上设置一个id可能会更清楚:

 var chart = highcharts({...
     yAxis: {            
        id: 'my_y',
     ...

 yAxis = chart.highcharts().get('my_y');
 yAxis.getExtremes();  // {min:, max:, dataMin:, dataMax:}
 yAxis.setExtremes(newmin, newmax);

fiddle

相关问题