HighCharts: subsequent chart erases previous chart


HighCharts: subsequent chart erases previous chart



I am having a problem of creating Highcharts dynamically - from asynchronous ajax calls: sometimes subsequent chart erases previous chart from a different container. This is the scenario:
1. From 6 to 8 charts are created simultaneously from ajax async data. Each chart is assigned to a dynamic array and destroys before rendering:


if (charts[chID] != null) {
charts[chID].destroy();
}



Then we create a chart:


charts[chID] = new Highcharts.Chart(chartOptions);



As I mentioned all these charts are created simultaneously from async ajax calls.
The problem is that some charts are missing after the first run; after that all charts are rendered properly. Debugging the code shows that the missing charts are actually created, but then erased by subsequent charts. The screenshots from Chrome dev. tools:
Three charts (4,5,6) are OK
Three charts (4,5,6) are OK



Then another chart (1) is added and erases chart 4:
chart (1) erases previously rendered chart (4)



These 'missing' charts happen quite irregularity - sometimes only one chart is missing, sometimes 2 or 3. Running the routine the second time always fixes the issue and all charts are rendered properly. I guess it is because the array charts is already created.



I tried skipping the chart destroy function, changing the chart array to object, initiating the array charts before, but nothing helped.



Note that the code doesn't generate any errors, no missing divs.



Any suggestions where to dig?



Thanks!





That sounds like renderTo (aka "container") is exactly the same for multiple chart - I would check that.
– Paweł Fus
Jun 29 at 11:36


renderTo





It was my initial thought also... but all containers are different and point to correct divs with unique IDs. Also, the second run always generates proper charts. The only difference between the 1st run and subsequent runs is that the charts array is empty. The 2nd run takes the created charts array from the 1st run, because charts is declared globally..
– user2723490
2 days ago





Ok, without live demo we can only guess what is wrong - please create one (e.g. jsfiddle or webpage). You mentioned: I tried skipping the chart destroy function (...) but nothing helped. - that suggests chart is there already, because Highcharts will destroy chart, if container already has one.
– Paweł Fus
2 days ago


I tried skipping the chart destroy function (...) but nothing helped.





Exactly, when debugging it step-by-step, I can see a correct chart rendered in div A and then erased after another chart is rendered in div B. I will try to create a demo, but it is difficult because of these async ajax calls to remote server. One more thing. I have the same code running correctly for years - the difference with this one is that the page is generated dynamically, but the old code used a loaded html file. I don't understand if it could affect it somehow, because all containers are already in place before rendering charts.
– user2723490
2 days ago





We can only guess.. Honestly, similar issues were reported before and in the end there was "aha! - duplicated container because of <<something>>". This something can be for example framework.
– Paweł Fus
2 days ago


<<something>>


something









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV