question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Legend onclick can not override chart onclick

See original GitHub issue

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) }}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
dpadulacommented, Nov 27, 2020

@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

0reactions
KhalidOuazcommented, Feb 27, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Legend onclick can not override chart onclick #299 - GitHub
Hi, I want trigger legend onclick function, but when I click legend, it seems to trigger the chart onclick function to setState. Is...
Read more >
Chart.JS custom legend onClick event returns error when ...
I'm trying to create custom onClick handler for pie chart legend and I get this error: ERROR TypeError: Cannot read property ...
Read more >
onClick of ui.chart, Properties Webix Docs - Documentation
... of ui.chart. This page contains onClick documentation to help in learning the library. ... the onClick handler can override the default onclick...
Read more >
Legend onClick override with default behaviour-Chart.js
The only issue with this fix is that by default, in ng2-charts the .hidden artibute is not exposed by default so i had...
Read more >
Legend Onclick Chart JS | ChartJS 2.9.x - YouTube
Legend Onclick Chart JS | ChartJS 2.9.x. In this video we will explore how to create an onclick event on the legend. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found