Stacked Bar Graphs - selecting row and dataset selected #9053
Unanswered
BuffaloBrennan
asked this question in
Q&A
Replies: 1 comment 3 replies
-
This is possible by using a custom onclick handler in V3 ike so: options: {
onClick: (evt,elements,chart) => {
const clickedPoint = chart.getElementsAtEventForMode(evt, 'nearest', { intersect: true }, true);
const label = chart.data.datasets[clickedPoint[0].datasetIndex].label;
alert(label)
}
} fiddle link: https://jsfiddle.net/Leelenaleee/y2rnophL/10/ For V2 you can achieve it like this: onClick: (evt,val) => {
const chart = val[0]._chart;
const clickedPoint = chart.getElementAtEvent(evt);
const label = chart.data.datasets[clickedPoint[0]._datasetIndex].label;
alert(label)
} Fiddle link: https://jsfiddle.net/Leelenaleee/1v5cwjy4/10/ |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Morning everyone
I've created a stacked bar graph, but I need a way of identifying which bar and section/element of the bar I've selected. I can work out the bar no problem. so in the following image that would be 4 - so I can retrieve the label "Report Edit Complete":
If I click on the pink I want to retrieve the label for the 3rd element "6-9 weeks"
Is there a way I can do this?
Beta Was this translation helpful? Give feedback.
All reactions