jbartlett777
Posts: 4
Joined: Tue Dec 08, 2020 9:06 pm

Maplines not rendering the same when added by addPoint instead of inline

I'm dynamically drawing a series of maplines while processing data and adding additional points to the series as it progresses. The lines are appearing and vanishing or not even being drawn but if I pass in the same points in the chart definition, it renders as expected.

Desired result with the points inline: https://jsfiddle.net/jbartlett777/egkfbp2y/
Image

Points added via Javascript: https://jsfiddle.net/jbartlett777/ujboe5c1/
Image
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Maplines not rendering the same when added by addPoint instead of inline

Hello, welcome to our forum and thanks for contacting us with your question!

The first chart differs from the second one because you are using the addPoint function In the wrong way.
when you check the API reference:

https://api.highcharts.com/class-refere ... s#addPoint

the addPoint function allows you to add single point to the function. Whereas you are trying to add a series of points at once.
What you can do, is to wrap all of the objects into the array, and using the forEach function add all of the points one by one.

The solution would look something like this:

Code: Select all

 

let array = [] // ... array of points, that you want to add

  array.forEach(point => {
    Map.series[0].addPoint(point, false);
  })

when you check the API, you can notice, that the addPoint function takes such parameters: addPoint(options [, redraw] [, shift] [, animation] [, withEvent])
where the second parameter is the redraw property. setting it to false will prevent redrawing the chart the number of times equal to the length of the array, and improve performance. Then you can call the chart.redraw() at the end, to apply the changes.


Let me know if that solution works for you, and in case of any further questions don't hesitate to contact us again!
Kind regards,
Paweł Lysy
Highcharts Developer
jbartlett777
Posts: 4
Joined: Tue Dec 08, 2020 9:06 pm

Re: Maplines not rendering the same when added by addPoint instead of inline

Thank you. Adding the new data one point at a time indeed did work. I think I saw a sample somewhere with a multi-comma point was added and I took it as a multi-point.
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Maplines not rendering the same when added by addPoint instead of inline

Good to hear, you made it work!
In case of any further questions feel free to contact us again!
Kind regards,
Paweł Lysy
Highcharts Developer

Return to “Highcharts Maps”