Interacting with axis labels #8591
famschopman
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to enable interaction with the axis labels. Clicking the axis label would enable a contextual menu with the ability to change the sorting order, aggregation type on measures, or change the way we present dates (e.g. original, by week, by month, by quarter). It is a very nice way of changing the presentation in a nice approachable way.
ChartJS does not support events on ticks and axis labels out of the box (it does on data points) so I have been looking on the best way to accomplish this. The chart object exposes a number of elements that can help. The chart.scales property provides access to labels, ticks, measurements and coordinates.
I want to separate the axis label, from the axis ticks. This enables me to position a regular DOM element on top of the rendered axis label that can also provide hover effects to emphasize to users that they can interact with the label to show a menu.
I have the rough basis ready, it's not rocket science but before I move on I wanted to validate with the community if someone else already build something similar that I can reuse, perhaps ChartJS has already hidden endpoints/extension points?
Either way, for others to use or learn, the rough basis I stitched together. I haven't yet checked what happens if the position was not explicitly defined on the axis etc. so the code is full of assumptions and possible unhandled weaknesses.
And it will look like this in my pet project.
Beta Was this translation helpful? Give feedback.
All reactions