score:0

Accepted answer

easyest way to do this is by removing all the data updating the chart, readding the data and the updating the chart again

const chart = new chart(ctx, options);

document.getelementbyid("tt").addeventlistener("click", () => {
  const datasets = chart.data.datasets;
  chart.data.datasets = [];
  chart.update();
  chart.data.datasets = datasets;
  chart.update();
})

live example:

var options = {
  type: 'doughnut',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
      label: '# of votes',
      data: [12, 19, 3, 5, 2, 3],
      borderwidth: 1,
      backgroundcolor: ["red", "blue", "yellow", "green", "purple", "orange"]
    }]
  },
  options: {
    scales: {}
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
const chart = new chart(ctx, options);

document.getelementbyid("tt").addeventlistener("click", () => {
  const datasets = chart.data.datasets;
  chart.data.datasets = [];
  chart.update();
  chart.data.datasets = datasets;
  chart.update();
})
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <button id="tt">
    reanimate
    </button>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.3.0/chart.js"></script>
</body>


Related Query

More Query from same tag