-
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
Change line colour on hover #3880
Comments
@kilouco have you looked at the tooltip modes sample? https://github.com/chartjs/Chart.js/blob/master/samples/tooltips/interaction-modes.html |
@etimberg yes I have. None of the examples give me any clue on how to achieve a background color change based on y position and values tooltip based on x position. Am I missing something? |
oh, sorry I misunderstood what you're looking for. At the moment, there is no way to change the style of the line (fill/stroke) on hover. Possible duplicate of #2136 |
I don't think it's a duplicate. He is asking for a change on line color on hover. I'm asking for a fill color change. The idea is pretty much the same, though. |
Hey, currently on 2.7.3 and wondering if this feature is still missing from Chart.js. With @types/chart.js I can see that the dataset takes a backgroundColor and hoveredBackgroundColor but does not apply it to the "stacked" lines. |
I'm stuck on this also, I need to be able to highlight the dataset with the line included. |
@kurkle looks like the dataset mode hover stopped working. Do you recall what happened to it? |
@etimberg looks like its working? |
So it is! I must have setup my test case wrong when I tried it locally. |
So, this is actually quite trivial to achieve using Chart.js v3 and a custom interaction mode: Chart.Interaction.modes.under = function(chart, e, options, useFinalPosition) {
const metas = myChart.getSortedVisibleDatasetMetas();
for(meta of metas) { // loop the metasets from top to bottom
if (meta.dataset.interpolate(e, 'x').y < e.y) { // the line is above mouse position
return [{datasetIndex: meta.index, element: meta.dataset}]; // could return all the points here too
};
}
return [];
}; |
Closing since the above solution works well |
I believe it would be nice to see a good interaction support with Stacked Line charts, where one could get a Tooltip and a background color change by hovering over the filling of a line.
The text was updated successfully, but these errors were encountered: