當我談到JavaScript時,我仍然非常溼潤。我需要一些幫助,將高收益的輔助軸添加到高收益圖表中,該高圖表也使用$ .getJSON(JSONP)來截斷json文件以填充數據。如何將輔助軸添加到highstock圖表中?
查看JSFiddle示例here。這裏是示例數據集with。最後,在Highcharts的例子secondary axis。
$(function() {
var seriesOptions = [],
seriesCounter = 0,
names = ['MSFT', 'AAPL', 'GOOG'],
// create the chart when all data is loaded
createChart = function() {
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function() {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
yAxis: {
floor: 0
},
plotOptions: {
series: {
compare: 'value'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
});
};
$.each(names, function (i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?', function (data) {
seriesOptions[i] = {
name: name,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter += 1;
if (seriesCounter === names.length) {
createChart();
}
});
});
});
任何幫助和解釋(所以我可以學習)非常感謝。我仍然試圖學習如何將jsonp和圖表綁定在一起,特別是多個數據和json文件系列。
次Y軸?如果是這樣,你只需要使用一個數組。例如:'yAxis:[{.. axis1 properties ..},{.. axis 2 properties ..}]'。只要注意,只要沒有連接到軸的系列,它就不會顯示標籤。只需將屬性「yAxis:n」添加到您的系列中,其中'n'是軸鍵(第一個是0,第二個是1 ...) – MorKadosh 2014-10-31 13:54:00
因此,我需要添加一個新的軸標籤並添加系列到理想的標籤。我之前嘗試添加新標籤,但沒有添加任何系列,因此沒有顯示任何內容。我想這就是爲什麼。 – Fastidious 2014-10-31 14:08:41
由於@MorKadosh說你需要有一個軸對象的數組,然後在這個系列對象中,請參閱particualr yAxis。 – 2014-10-31 14:20:42