chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.9k stars 11.88k forks source link

How can I click outside and trigger the onClick of legend event? #11784

Closed CuongSofi closed 1 month ago

CuongSofi commented 1 month ago

Feature Proposal

Ảnh màn hình 2024-05-22 lúc 11 24 06

Possible Implementation

If option "TRAM_LU_QUET_02" is not selected , I want legend of chart have color orange still not select. I don't know trigger event onClick outside. Thanks ! Ảnh màn hình 2024-05-22 lúc 11 32 26

LeeLenaleee commented 1 month ago

For these kind of questions please head over to stack overflow. But what you need to do is store your chart in a variable and then you can do the exact same logic as you do in the onClick handler.

stockiNail commented 1 month ago

@CuongSofi I don't think you need to catch the click event outside of the canvas. When something change in the list box you have to select the datasets, you can invoke chart.update() where the legend plugin is configured to reflect what is selected in list box.

codepen: https://codepen.io/stockinail/pen/MWdyNyj

@LeeLenaleee apologize, I had already started the codepen before your feedback.

LeeLenaleee commented 1 month ago

No problem :)