Search code examples
javascripthtmlanychart

JS function create multiple div when running with new data


I am really new to HTML and working on this simple task for hours.

I have dynamic data that use it to create a word cloud, the problem is when data changes, my js function make a new div and therefore a new word cloud but I want to update the last one, something look dynamic.

here is my js code:

function foo(){
    <!--some other things-->
   anychart.onDocumentReady(function () {
   var chart = anychart.tagCloud(word_cloud);
   chart.title('Word relevancy map')
   chart.angles([0])
   chart.container("container");
   chart.draw();
    });
}

and my HTML container is like this:

<div id="container"  class="col-lg-8"  width=" 100%" height="800">

any help is appreciated<3


Solution

  • There is no need to recreate the chart completely to update the data. The best practice here is to apply new data to the existing chart. For details check the sample.