2

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

根据 API 参考,如果y-axis = {max:null}缩放是自动的。但是如果我锁定比例,我必须以某种方式提取 y 轴比例,以便我可以手动将 y 轴设置为当前值。当我切换回 y 轴设置为空。

无论如何,当它设置为空时,是否可以提取 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
}
4

1 回答 1

5

当然,您可以通过调用 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);

小提琴

于 2013-08-11T18:00:52.080 回答