【问题标题】:Changing data in HighCharts series causes y-axis to blow up更改 HighCharts 系列中的数据会导致 y 轴爆炸
【发布时间】:2011-11-25 23:03:49
【问题描述】:

我在 Highcharts 折线图中看到了一些奇怪的行为。我显示了多个系列,需要让用户更改图表上所谓的“地图级别”,这是一条跨越所有时间段的直线。假设正确的系列是

chart.series[i]

并且我希望它设置的新级别存储在 var newMapLevel 中, 我正在像这样更改该系列的数据:

data = chart.series[i].data;
for(j=0; j<data.length; j++){
    data[j].y = newMapLevel;                    
}
chart.series[i].setData(data);

调用此函数具有预期的效果,除非新地图级别 y_value 比所有其他系列的最高 y_value 大 1,在这种情况下,y 轴刻度会爆炸。换句话说,如果 y_axis 比例通常是从 0 到 275,000,并且任何其他系列的最高 y_value 是 224,000,则将新地图级别值设置为 224,001 会导致 y_axis 比例变为 0 到 27500M。是的,这是 275 亿。

这可能是 Highcharts 中的错误吗?或者有没有更好的方法来更改系列中的数据?

我已经发布了一个小提琴:http://jsfiddle.net/earachefl/4FuNE/4/

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    我从 Highcharts 论坛得到了答案:

    http://highslide.com/forum/viewtopic.php?f=9&t=13594&p=59888#p59888

    【讨论】:

      【解决方案2】:

      这并不像我希望的那样顺利。当您从 8 作为您的线变为 2 作为您的线时,比例不会向下调整,直到您输入另一个值。也许这是一个正确方向的开始。

      $(document).ready(function(){
      $('#clickme').click(function(){      
          var newMapLevel = $('#newMAP').val();
          if(newMapLevel){
              for(i=0; i<chart.series.length; i++){
                  if(chart.series[i].name == 'Map Level'){
                      data = chart.series[i].data;
                      for(j=0; j<data.length; j++){
                          data[j].y = newMapLevel;                    
                      }
      
                     // get the extremes
                      var extremes = chart.yAxis[0].getExtremes(); 
                      //alert("dataMin: " + extremes.dataMin);
                      //alert("dataMax: " + extremes.dataMax);
      
                      // define a max YAxis value to use when setting the extremes
                      var myYMax = extremes.dataMax; 
                      if (newMapLevel >= myYMax) {
                          myYMax = Number(newMapLevel) + 1; // number conversion required
                      }
      
                      if (myYMax > chart.yAxis[0].max) {
                          alert('cabbbie'); 
                          myYMax = chart.yAxis[0].max + 1; 
                      }
      
                      //alert("myYMax: " + myYMax);
      
                      chart.yAxis[0].setExtremes(extremes.dataMin, myYMax)     
      
                       // finally, set the line data
                      chart.series[i].setData(data);                     
                  }
              }
          }
      }); });
      

      【讨论】:

      • 是的,我今天刚刚看到了在轴上设置极端的可能性 - 我会尽快尝试。
      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 2012-04-27
      • 2015-02-10
      • 2015-06-11
      • 2019-01-15
      • 2013-05-12
      相关资源
      最近更新 更多