Plugin Element div corrupted on data refresh

Hello community,

I’m a complete beginner in Bubble, Plugin writing and JavaScript so bear with me if this question is too simple or obvious. :blush:
I am using JS charting libraries from amCharts to draw a customized type of diagram and after cracking all the required parameters, library standards and Bubble Plugin rules I was able to draw a beautiful graph inside the div created for this Element.

However I am struggling with the refresh of this same diagram. Once the graph is drawn and I want to redraw it upon changes on the associated data I have only found one way to do it: Page Refresh.
What I have tried:

  1. I tried to make the conditions in the Update script to be more flexible but my code is basically drawing the graph on top of the previous graph.
  2. I tried an Element Action to execute the same code that draws the chart again. This action is triggered from the application when data is changed. The result is the same, a new graph is drawn on top of the previous one or just some characters.

I’m guessing I should do something with the original div, destroy, delete, recreate, or perhaps flush the instance.canvas element. However I can’t find documentation about this element and I’m not sure this is the right approach.

Would any patient Bubble/JS experienced user help me to overcome this problem?