Skip to content
Advertisement

Chart.js OnClick event with a mixed chart, which chart did I click?

EDIT: Modified to add options, and a suggested (from the answer) chartClickEvent, here is a jsfiddle: http://jsfiddle.net/jmpxgufu/174/

Imagine if you will a Chart.js mixed chart with the following config:

JavaScript

As my chartClickEvent says, my array is length 2, because I have two charts. That’s great and all, but I have no idea how to figure out whether to use array[0] or array[1]. If they click specifically the line data point, I want to do something with that data (array[0]), if they click the big blue bar, I want to do something with that data (array[1]). How do I tell whether they clicked on the line or the bar?

Thank you.

Advertisement

Answer

HTML

JavaScript

JS

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement