用Highcharts如何动态向一个序列添加点-示列讲解

发布时间:2026/8/7 7:52:02
用Highcharts如何动态向一个序列添加点-示列讲解 动态向 Highcharts 序列添加点通常用series.addPoint()。最常见写法是Highcharts.chart(container,{chart:{type:line},title:{text:动态添加点},xAxis:{type:datetime},series:[{name:随机数据,data:[[Date.UTC(2026,7,5,10,0,0),10],[Date.UTC(2026,7,5,10,1,0),12]]}]});setInterval(function(){constchartHighcharts.charts[0];constserieschart.series[0];constx(newDate()).getTime();constyMath.round(Math.random()*100);series.addPoint([x,y],true,false);},1000);参数说明series.addPoint(point, redraw, shift, animation)point要添加的数据点例如12、[x, y]或对象{ x, y }redraw是否立即重绘通常设为trueshift是否移除最早的一个点适合实时曲线animation是否动画更新实时折线常见用法如果你希望图表像监控面板一样持续滚动可以用series.addPoint([x,y],true,true);这样每添加一个新点就会移除最旧的点。官方文档series.addPoint: https://api.highcharts.com/class-reference/Highcharts.Series#addPoint实时数据示例: https://www.highcharts.com/docs/working-with-data/live-data