Skip to content
Advertisement

ApexCharts.exec updateSeries works only once

Have an issue that I’m trying to figure out with Apexcharts.

just to lead with, I cant really post an example as the chart code is somewhat large and relies an web-sockets to get the data so I’m going to try my best to explain the flow with hopes somebody may know what I’m doing wrong here, I apologies in advance.

The flow of the application is

  1. User can view the results of a survey ( this is using apex charts ). This is a modal window that opens and builds an on-the-fly popup that contains the chart div e.g

    <div class="poll[dynamic number"></div>  
    
  2. User has the results view opened (this renders just fine) and a new response comes in

  3. data comes in and we use

    ApexCharts.exec(chartName, 'updateSeries', [{
       data: updateData
     }], true);
    

To update the data. This works great the first time, however if we close the modal, open it back up again the chart renders just fine but new responses don’t update the chart.

Looking at the code there are no duplicate ID’s, so when the modal is opened its fully replacing the content of the popup, as noted the chart renders just fine each time but subsequent updateSeries don’t work. printing things to the console show the data coming in, it appears it can get the chart object however updates don’t seem to work.

Reloading the page will get the updates to work so I’m thinking it may be something with how its being initiated however trying to destroy the charts before etc have change nothing.

I know this is a very hard to debug without seeing and if I could post an example I would. I guess the question really is, should apex charts updateSeries work with multiple dynamically generated charts? If not, then why does it work once and never again?

Advertisement

Answer

Ok, just in-case anyone else runs into this issue I was able to get this resolved.

Basically in our code we were reusing a variable, then rendering the chart however by doing so the original chart object was not getting destroyed before creating the new one. ( maybe this apex charts should catch this as one would think chartID would be unique and when creating a new chart it would look for the chartID first, before creating a new object )

Anyhow we moved this to be their own dynamic variables so we can check if the chart is there first and alway destroy that object before creating a new one.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement