title: Apexcharts remove old data series before render new series
body: <p>I'm using apex chart for simple data visualization from json output. My charts based on pure javascript and not Vue or other frameworks. </p>
  
  <p>My json (php) backend create two json outputs fro draw the chart as below</p>
  
  <p>JSON 1</p>
  
  <pre><code>{
      "x": "2019-05-27 16:18:48",
      "y": "100"
  },
  {
      "x": "2019-05-27 16:25:09",
      "y": "110"
  },
  </code></pre>
  
  <p>JSON 2</p>
  
  <pre><code>{
          "x": "2019-05-27 16:18:48",
          "y": "60"
      },
      {
          "x": "2019-05-27 16:25:09",
          "y": "65"
      },
  </code></pre>
  
  <p>Based on the above two json outputs I retrieve data and draw my graph using the Category paired values method. below is the code responsible for retrieve data and draw the chart.</p>
  
  <p>function for getting json data</p>
  
  <pre><code>function data_function(){
              $.ajax({
                  type: "Get",
                      url: backend,
                      data:{
                          param: "all_a"
                      },
                      async: true,
                      cache: false,
                      success: function(data) {
                          a_data = data;
  
                          $.ajax({
                          apex_task: "Get",
                              url: backend,
                              data:{
                                  param: "all_b"
                              },
                              async: true,
                              cache: false,
                              success: function(data) {
                                      b_data = data;
                                      chart(a_data,b_data);
  
                              }
                          });
                      }
              });
  }
  </code></pre>
  
  <p>function for draw chart</p>
  
  <pre><code>function draw_chart(a_data,b_data) {               
      var options = {
  
              chart: {
              height: 400,
              type: 'bar',
              stacked: false
              },
              series: [
              {
                  name: 'a',
                  data: a_data, 
              },
  
              {
                  name: 'b',
                  data: b_data, 
              }],
  
              yaxis: [
               {
                  axisTicks: {
                  show: true,
                  },
                  axisBorder: {
                  show: true,
                  color: '#008FFB'
                  },
                  labels: {
                  style: {
                      color: '#008FFB',
                  }
                  }
  
                      },
              ]
      }
  
      var chart = new ApexCharts(document.querySelector("#chartdiv"), options);
      chart.render(); 
  }
  </code></pre>
  
  <p>This works fine until I second time render the chart with new data. when I load the different data without reloading the windows chart happen to be laggy and render multiple times with the old incorrect data. sometimes I have to run the data_fnction multiple times to render the chart properly. </p>
  
  <p>How can I fix this? Do I need to use function like appendchart ? how can I use wiht my data_function </p>