我正在使用highcharts和實時數據。我看到這個例子,它爲我工作得很好:Highcharts with live data:在左側對齊圖表
https://www.highcharts.com/docs/working-with-data/live-data
但我想對齊左側的線,即使我有幾點畫。可能嗎?
我正在使用highcharts和實時數據。我看到這個例子,它爲我工作得很好:Highcharts with live data:在左側對齊圖表
https://www.highcharts.com/docs/working-with-data/live-data
但我想對齊左側的線,即使我有幾點畫。可能嗎?
這裏的一個問題是xAxis
對象的maxZoom
屬性。使用它可以指定最小範圍xAxis
,該範圍已存在:maxZoom
設置爲20000
。要將點對齊到左側,您可以從配置中刪除此屬性。這是我編輯的這個小提琴的版本:https://jsfiddle.net/arcquim/y9eaw1rf/13/。
如果你想保持maxZoom(minRange實際)屬性,你需要在第一個點的添加時設置axis min,當你開始移動點時 - 你應該重置min,這樣圖表就能夠改變它的極值。
load: function() {
// set up the updating of the chart each second
var chart = this;
var series = this.series[0];
var minSet = false;
var extremesReset = false;
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100);
if (!minSet) {
chart.xAxis[0].update({
min: x
}, false);
minSet = true;
}
if (series.data.length > 20 && !extremesReset) {
chart.xAxis[0].update({
min: null,
}, false)
extremesReset = true;
}
series.addPoint([x, y], true, series.data.length > 20, series.data.length);
}, 1000);
}