我正在绘制3D折线图。每次计数在循环结束时更改时,都会为每个系列绘制一个新点。有没有办法在我的示例代码中将图例的值设置为count的值?该计数表示自实验开始以来的小时数,因此必须能够显示。谢谢!
events: {
load: function() {
var thischart = this;
for (i = 0; i < allpoints.length; i++) {
thischart.addSeries({
enableMouseTracking: false,
lineWidth: 1,
marker: {
enabled: false
},
data: [0, 0, 0]
}, false)
thischart.redraw(false);
}
setInterval(function() {
if (count >= max_data_length) {
if (!pause_at_end) {
for (i = 0; i < allpoints.length; i++) {
thischart.series[i + marker_series_length].setData([0, 0, 0], false);
}
thischart.redraw(false);
count = 1;
} else {
is_paused = true;
document.getElementById('pauseit').value = "Unpause";
}
}
if (!is_paused) {
for (i = 0; i < allpoints.length; i++) {
if (allpoints[i].length > count) {
thischart.series[i + marker_series_length].addPoint([
allpoints[i][count][0], allpoints[i][count][2], allpoints[i][count][1]
], false);
}
}
thischart.redraw(false);
count = count + 4;
}
}, 10)
}
}
答案 0 :(得分:0)
您可以使用series.update
方法设置新数据并在图例中更改系列名称:
chart: {
...,
events: {
load: function() {
var counter = 0,
series = this.series[0];
setInterval(function() {
counter++;
series.update({
data: getRandomData(),
name: 'Name ' + counter
});
}, 1000);
}
}
}
实时演示: https://jsfiddle.net/BlackLabel/7bq21tak/
API参考: https://api.highcharts.com/class-reference/Highcharts.Series#update
答案 1 :(得分:0)
感谢ppotaczek!这为我指明了正确的方向。我改用chart.update来更新字幕。这是我使用的代码:
chart.update({
chart: {
inverted: false,
polar: false
},
subtitle: {
style: {
fontSize: '20px'
},
text:'Day:'+ countdays
}
});