Legend onclick can not override chart onclick
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)
}}
I have this issue too - any update about that?
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 .
Please refer to the chart.js docs: https://www.chartjs.org/docs/latest/configuration/legend.html#custom-on-click-actions
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
@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