-1

I have multiple charts in a single page and i wanted to add a custom onClick action to the charts. Below code is from chart.js documentation. It shows how to add the action when there is a single chart https://www.chartjs.org/docs/latest/configuration/legend.html#custom-on-click-actions

How do I get access to the chart on which the user clicked to update the single chart when there are multiple charts?

onClick: function(e, legendItem) {
    var index = legendItem.datasetIndex;
    var ci = this.chart;
    var meta = ci.getDatasetMeta(index);

    // See controller.isDatasetVisible comment
    meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;

    // We hid a dataset ... rerender the chart
    ci.update();
}
tommueller
  • 2,358
  • 2
  • 32
  • 44

1 Answers1

0

Nevermind.

‘this.chart’ gives us access to the current chart even if we have multiple charts on the same page