-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mouse Click Events in ChartJS 2.X #2292
Comments
@ckoeber the returned objects will be points / bars / arcs depending on the chart type. If you look in the |
I have a doughnut chart and am trying to use the activePoint = chart.getElementAtEvent(evt) to get the element clicked (in this case the slice). When I do a console.log(activePoint) it shows the same object no matter which slice I click on. I just need to get the information about the slice (label, value) that was clicked. The _view and _model values always return the info about the 1st dataset not the one clicked. The getDatasetAtEvent returns all the slices objects but that doesn't help since I only care about the one clicked. I know I am probably missing something obvious here. Any help would be appreciated. Thanks! |
I too am looking to do the same as @kissgs Also, the ChartElement returned by getElementAtEvent seems to have all it's properties prefixed with an underscore which feels like they're for internal use only. It would be great if ChartElement exposed a formal (documented) API for extracting the underlying data. |
This works for me: FIDDLE INCLUDED
|
I'm implementing a click feature as provided by @dangre00 and have run into an issue when the chart is reloaded. It's a Vue.js component that allows filtering the chart data with a select box. The initial page load functions properly and the label and value are logged to the console in my case, but when I refresh the data with AJAX, I get really sporadic behavior. Clicks will return multiple data sets, or undefined. If I click around between bars in the chart they will return different results at random. My Vue component is below. Any suggestions on fixing the click events when the chart is reloaded?
}` |
when using multiple datasets in a bar chart |
How do i get the clicked point instead of first? Edit:
|
Here is a solution, $scope.onClick = function (points, evt) { |
Lil rough but this worked for me: |
How can I use the onclick event for a chart with multiple series? |
Hello,
I have been attempting to write mouse click events for a pie chart in ChartJS 2.X but the "getSegmentsAtEvent(evt)" function doesn't seem to be available in the newer version.
Instead, I have getDataelementAtEvenyt(evt), getElementAtEvent(evt), and getElementsAtEvent(evt).
The problem is I am not sure how to use the object returned; it doesn't have any of the previous types of functions/data that the existing object returned used to have.
How do I use the new objects/classes returned?
Thank you for your time.
The text was updated successfully, but these errors were encountered: