javascript - highchart - irregular time series -


i trying plot irregular time series data onto high chart such example http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/spline-irregular-time/.

var dataarray = [ {errordate: "2017-09-07", brand: "toyota", count: 3}, {errordate: "2017-09-02", brand: "ford", count: 258}, {errordate: "2017-09-03", brand: "ford", count: 239}, {errordate: "2017-09-04", brand: "ford", count: 197}, {errordate: "2017-09-05", brand: "ford", count: 187}, {errordate: "2017-09-06", brand: "ford", count: 418}, {errordate: "2017-09-07", brand: "ford", count: 344}, {errordate: "2017-09-03", brand: "mercedes", count: 43}, {errordate: "2017-09-04", brand: "mercedes", count: 220}, {errordate: "2017-09-03", brand: "chrysler", count: 3}, {errordate: "2017-09-04", brand: "chrysler", count: 3}, {errordate: "2017-09-06", brand: "chrysler", count: 6}, {errordate: "2017-09-07", brand: "chrysler", count: 1} ]; 

i have data in variable dataarray, , i've attempted build out series data based on each brand data coming in, challenge having need dynamically pass in 'errordate' along each data point in series plotted appropriately.

what best way accomplish this?

fiddle: https://jsfiddle.net/ntt5oc21/

you should prepare data before passing highcharts. doc page should helpful: https://www.highcharts.com/docs/chart-concepts/series

here processed data:

var seriesarr = []; dataarray.foreach(function(point) {    var newpoint = [point.errordate, point.count],     seriesindex = seriesarr.findindex((series) => series.name === point.brand);    if (seriesindex === -1) {     seriesarr.push({       name: point.brand,       data: [newpoint]     });    } else {     seriesarr[seriesindex].data.push(newpoint);   } }); 

then can use 1 of methods methods , properties dynamically modifying chart api section: http://api.highcharts.com/highcharts

for example:

seriesarr.foreach(function(series) {     chart.addseries(series); }); 

full demo: https://jsfiddle.net/kkulig/knhx3yvz/


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -