George Shalvashvili
George Shalvashvili

Reputation: 1560

Highcharts addPoint does not draw line in sequence of provided data

i want to draw the line by the order of data. Data is added dynamically so i am using addPoint. for example i have this:

let data = [[1,2], [5,3], [2,5]]

chart.series[0].addPoint(data[0])
chart.series[0].addPoint(data[1])
chart.series[0].addPoint(data[2])

and the result is that all the points on the chart are connected sequentially.

but i want it to be like this:

enter image description here

I made that chart by setData, but creating a separate array and repeatedly calling setData seems to be not the correct way. is there a way to achieve that with addPoint? or any other solution?

Upvotes: 0

Views: 218

Answers (1)

ppotaczek
ppotaczek

Reputation: 39099

You can use scatter series type with lineWidth property:

let data = [
    [1, 2],
    [5, 3],
    [2, 5]
]

let chart = Highcharts.chart('container', {
    series: [{
        type: 'scatter',
        lineWidth: 2,
        data: []
    }]
});


chart.series[0].addPoint(data[0]);
chart.series[0].addPoint(data[1]);
chart.series[0].addPoint(data[2]);

Live demo: http://jsfiddle.net/BlackLabel/ynrkq40g/

API Reference: https://api.highcharts.com/highcharts/series.scatter.lineWidth

Upvotes: 1

Related Questions