简体   繁体   中英

How do I add an array of data points to a Highchart series

I have a requirement where I get chunks of data asynchronously. When i get the first chunk, I create a new series but for all other chunks. I want to add the chunk of data to the existing series. I can see in Highcharts documentation, there is addpoint method, but it adds each point and this would take a long time. Is there a way to add a chunk of data to the series in one go. In my case each chunk of data is an array of 2500 data points.

Thanks in advance.

In the ajax callback just get the existing serial data, append whatever data you need to the series, and re-set the series data.

callback: 
function(msg) {
    var oldData = myChart.get('mySeriesName').data;
    var newData = formatMsgForHighCharts(msg);
    var combinedData= oldData.concat(newData);
    myChart.get('mySeriesName').setData(combinedData);
}

The line:

 var newData = formatMsgForHighCharts(msg); 

doesn't need to be there if the message is already formatted properly, just pass msg.d into the concat function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM