title: Update chart in Chart js
body: <pre><code>import Chart from "chart.js"
  
  let AnalyticsChart = {
  
    buildChart() {
      let ctx = document.getElementById("analyticsChart");
      let labels = ["sent", "delivered", "undelivered", "clicks"];
  
      let total_sent = parseInt(document.getElementById("total-sent").dataset.totalSent);
      let delivered = parseInt(document.getElementById("deilvered-count").dataset.deliveredCount);
      let undelivered = parseInt(document.getElementById("undelivered-count").dataset.undeliveredCount);
      let clicks = parseInt(document.getElementById("total-clicks").dataset.totalClicks);
      let counts = [total_sent, delivered, undelivered, clicks]
      let chart = new Chart(ctx, {
        type: 'doughnut',
        data: {
          labels: labels,
          datasets: [{
            data: counts,
            backgroundColor: [
  
              'rgba(54, 162, 235, 0.5)',
              'rgba(255, 206, 86, 0.5)',
              'rgba(255, 99, 132, 0.5)',
              'rgba(75, 192, 192, 0.5)'
            ]
          }] 
        },
        options: {
  
        }
      });
  
    },
  
    update(){
  
    }
  }
  
  
  export default AnalyticsChart
  </code></pre>
  
  <p>in this code I want to add update function to update chart.
  I want to pass chart variable to update function how can I do this?</p>
  
  <p>like this</p>
  
  <pre><code>update(chart) {
      let total_sent = parseInt(document.getElementById("total-sent").dataset.totalSent);
      let delivered = parseInt(document.getElementById("deilvered-count").dataset.deliveredCount);
      let undelivered = parseInt(document.getElementById("undelivered-count").dataset.undeliveredCount);
      let clicks = parseInt(document.getElementById("total-clicks").dataset.totalClicks);
      let counts = [total_sent, delivered, undelivered, clicks]
  
      chart.data.datasets.forEach((dataset) =&gt; {
          dataset.data.push(counts) # How can I put individual counts value?
      });
      chart.update();
  }
  </code></pre>
  
  <p>My questions 
  1. How can I pass chart variable in buildChart() to update function as parameter.
  2. how can I put individual counts element in dataset.data.push(counts)?</p>