Chartjs-Decrease bar spacing chartJS v2

1👍

There is a chart helper API which stores all the instances of a chart for a particular page. You can make use of that to find out if there is nothing present then create logic else update logic.

See the sample below. This is not the most refined logic but just to give an idea.

 var chartUpdated  = false;

Chart.helpers.each(Chart.instances, function(instance) {
  if (instance.chart.canvas.id === "yourCanvasId") {
    //perform the update logic
    chartUpdated = true;
    return;
  }  
});

if(!chartUpdated)
{
    //perform the create logic
}

Leave a comment