Chartjs-Chart.js load new data

1๐Ÿ‘

โœ…

I found a solution to your problem using an up to date version of Charts.js

Using destroy and storing your datas in an array. When you click on the control, it destroys the chart and rebuild a new one with the selected data

var mychart = new Chart(ctx,config);
$('.selector').click(function(){
 data.datasets = [datasets[$(this).data('index')]];
 if(mychart!== null){
      mychart.destroy();
      mychart = new Chart(ctx, config);
 }
 });

See the updated fiddle here : https://jsfiddle.net/3563ko2t/6/

Leave a comment