2014-02-20 57 views
0

您可以在plotBands中使用「通配符」和「最小值/最大值」來計算值嗎?更改圖表創建後的plotBands選項

像這裏http://jsfiddle.net/CBE9R/1/

$(function() { 
    $('#container').highcharts({ 
     chart: { 
     }, 
     xAxis: {   

      tickInterval: 24 * 3600 * 1000, // one day 
      type: 'datetime' 
     }, 
     yAxis: { 
      plotBands: [{ 
       color: 'green', 
       from: 150, 
       to: '' 
       },{ 
       color: 'red', 
       from: '', 
       to: '150' 
       }] 
     }, 

     series: [{ 
      data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4], 
      pointStart: Date.UTC(2010, 0, 1), 
      pointInterval: 24 * 3600 * 1000 
     }] 
    }); 
}); 

在不知道圖表的最小/最大值是有辦法例如紅色從底部到150和從150到頂部作爲綠色設置?

回答

1

它可以使用API​​來完成圖表被渲染後:

var chart = $('#container').highcharts(); 
var extremes = chart.yAxis[0].getExtremes(); 
var maxY = extremes.max; 
var minY = extremes.min; 

chart.yAxis[0].addPlotBand({ 
      color: 'green', 
      from: 150, 
      to: maxY 
}); 
chart.yAxis[0].addPlotBand({ 
      color: 'red', 
      from: minY, 
      to: '150' 
}); 

函數軸線getExtremes()返回電流極端(DATAMAX,dataMin,最大和最小軸值)。這些值用於設置合適的頻段。注意:如果硬編碼值(150)介於minY和maxY之間,則應進行額外的檢查。

查看更新example at jsfiddle

+0

我認爲這只是創建*(而不是改變)圖表創建後的繪圖帶。 – gubby

+0

是的......問的問題是你是否可以獲得並編輯現有的情節樂隊。這個被接受的答案並沒有告訴你如何去做。 – spetz83

相關問題