title: How Refresh chart js data with same variable name
body: <p>I am facing an issue while refreshing the data using the same variable. Every time data get changed in a variable(<strong>mydata</strong>) but after an update the chart loaded with same data.while click the refresh button chart get reloded but always showing the old chart in chart</p>
  <pre><code>&lt;button type=&quot;button&quot; onclick=&quot;refresh()&quot;&gt;Refresh&lt;/button&gt; 
      &lt;canvas id=&quot;mychart&quot;&gt;&lt;/canvas&gt;
      &lt;script &gt;
          var config = {
              type: 'bar',
              options: {
                  scales: {
                      y: {
                          beginAtZero: true
                      }
                  }
              },
          };
          var myChart=null;     
  function refresh(){
      $.ajax({
                  url: '/mydata',
                  method: 'POST',
                  data: {&quot;user&quot;:user},
                  async: false,
                  success: function(data) {
                      mydata = data;
                  }
              })
      config.data = {
              labels: [&quot;jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;may&quot;,&quot;june&quot;,&quot;july&quot;],
              datasets:
                 [{
                    data: mydata,
                    backgroundColor: [
                      'rgba(255, 99, 132, 0.2)',
                      'rgba(255, 159, 64, 0.2)',
                      'rgba(255, 205, 86, 0.2)',
                      'rgba(75, 192, 192, 0.2)',
                      'rgba(54, 162, 235, 0.2)',
                      'rgba(153, 102, 255, 0.2)',
                      'rgba(201, 203, 207, 0.2)'
                  ],
                  borderColor: [
                      'rgb(255, 99, 132)',
                      'rgb(255, 159, 64)',
                      'rgb(255, 205, 86)',
                      'rgb(75, 192, 192)',
                      'rgb(54, 162, 235)',
                      'rgb(153, 102, 255)',
                      'rgb(201, 203, 207)'
                  ]
                 }]
           };
           ctx = document.getElementById('mychart');
      if(myChart == null){
          myChart = new Chart(ctx, config);
      } else{
      myChart.data.datasets[0].data=mydata;
         myChart.update();
      }
  
  }
          
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>