[Chartjs]-ChartJS Update callbacks

4👍

Instead of modifying your callbacks why not using a condition inside them, testing a global variable?

For example:

tooltips: {
  mode: 'index',
  intersect: false,
  callbacks: {
    label: function (tooltipItems, data) {
      if (percent)
        return addCommas(tooltipItems.xLabel) + "%";
      else
        return addCommas(tooltipItems.xLabel);
    }
  }
},

Here is a jsfiddle showing this approach:
https://jsfiddle.net/beaver71/nk6rz1f3/

Leave a comment