2014-03-05 24 views
0

我想根據頂部繪圖線的位置動態調整HighCharts折線圖上的背景圖像的大小。我想要調整的圖像是下圖中的鐘形曲線。在HIghCharts.js中查找繪圖線的Y軸值

Chart with image

我不能設置圖像的高度爲靜態值,因爲屏幕的大小可以改變和頂情節也隨時間而變化。

目前我設置的情節線,外部函數的位置是這樣的:

plotLines: [ 
       value: upperControl3()}, { 
       color: '#ccc', 
       zIndex: 3, 
       width: 1, 
       label: { 
        text: '-2s', 
        x: 520, 
        y: 3 
       } 

最接近的頂端情節主線的y值我已經能夠找到的是一個DATAMAX值,但這對每個圖表負載都保持不變。 我一直在試圖覆蓋和尺寸的圖像與功能在這樣的圖表的末端:

function(chart) { 

    console.log(chart.yAxis[0].plotLinesAndBands[7].axis.plotLinesAndBands[0].axis); 

    var h = chart.yAxis[0].plotLinesAndBands[7].axis.plotLinesAndBands[0].axis.dataMax; 

    var y = chart.yAxis[0].axisTitle.y + extra; 

    // X, Y, Width, Height 
    chart.renderer.image('images/bell.jpg', 60, y, 200, h).add(); 

} 

是在沒有辦法找到一個highcharts情節的座標?

+0

是固定在上Y軸的一些特定值的繪圖線或它動態地改變它。你保持yAxis價值嗎? – Strikers

回答

3

您可以使用plotLinesAndBands對象,其中plotlines被保留。在有價值的選項中,可以通過toPixels函數將其轉換爲像素值。

var $button = $('#button'), 
    $report = $('#report'), 
    chart = $('#container').highcharts(); 

$button.click(function() { 
    chart.xAxis[0].addPlotLine({ 
     value: 5.5, 
     color: 'red', 
     width: 2, 
     id: 'plot-line-1' 
    }); 

    var plotline = chart.xAxis[0].plotLinesAndBands[0]; 

    $report.html('Value: ' + plotline.options.value + ' Pixels: ' + chart.xAxis[0].toPixels(plotline.options.value)); 
}); 

http://jsfiddle.net/HhP39/1/

2

如果你知道哪些情節線(通過索引)是,你可以這樣做:

chart.yAxis[0].plotLinesAndBands[0].options.value 

當然,你需要確保你的數據實際上是正態分佈的,否則,正常的曲線方式什麼也沒有:)

零邊界數據通常不正常分佈。