react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Legend onclick can not override chart onclick

Open luqiwang opened this issue 8 years ago • 5 comments

Hi, I want trigger legend onclick function, but when I click legend, it seems to trigger the chart onclick function to setState. Is there any way to prevent chart onclick when click the legend. Thanks a lot! options = {legend: { display: true, onClick: (e, item) => {console.log("Click Legend")} }, events: ['click', 'mousemove'], onClick: (e, data) => { this.setState(newState) }}

luqiwang avatar Jun 20 '18 20:06 luqiwang

I have this issue too - any update about that?

erezLieberman avatar Feb 12 '19 19:02 erezLieberman

Sorry, I cannot find one.

On Tue, Feb 12, 2019 at 11:02 AM Erez Lieberman [email protected] wrote:

I have this issue too - any update about that?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jerairrest/react-chartjs-2/issues/299#issuecomment-462889980, or mute the thread https://github.com/notifications/unsubscribe-auth/Ag5GYqx-Px_kGLnubLvpXUYUr7GkLY2kks5vMw-sgaJpZM4Uv9ws .

luqiwang avatar Feb 12 '19 20:02 luqiwang

Please refer to the chart.js docs: https://www.chartjs.org/docs/latest/configuration/legend.html#custom-on-click-actions

pringelmann avatar Dec 10 '19 17:12 pringelmann

Hello Button continue to be override, i have a test here but i am still not finding a solution. Can you help me please https://codesandbox.io/s/gallant-archimedes-zqxre

c2troie avatar Feb 27 '20 14:02 c2troie

@KhalidOuaz I've found this and test it with another chart (bar chart). Maybe can help you with the behavior of legend.

legend: { display: true, position: 'bottom', onClick: (e, legendItem, chart) => { // console.log('e', e); // EVENT // console.log('legendItem', legendItem); // ITEMS // console.log('chartRef'); // REF const ci = chartRef.chartInstance; let meta = ci.getDatasetMeta(0); // console.log(meta);

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

  // // We hide a dataset ... rerender the chart
  ci.update();
},

Cheers

dpadula avatar Nov 27 '20 12:11 dpadula