Skip to content
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

Center point labels to slices in polar chart #9662

Closed
peteruithoven opened this issue Sep 19, 2021 · 4 comments · Fixed by #9949
Closed

Center point labels to slices in polar chart #9662

peteruithoven opened this issue Sep 19, 2021 · 4 comments · Fixed by #9949

Comments

@peteruithoven
Copy link

Feature Proposal

Aligning point labels to slices of a polar chart:
Screenshot from 2021-09-20 00-34-55@2x

Currently point labels of a polar chart are drawn in line with the angle lines:
Screenshot from 2021-09-20 00-28-05@2x

Feature Use Case

For labeling the different slices, instead of using a legend and colors, I'd like to use point labels but center align them to the pie slices, like:
I need to label / explain which slice is what. Instead of relying on a legend and colors I'd like to add labels next to the slices. Using point labels comes close, but their position is confusing.

Possible Implementation

A new property that allows aligning the point labels differently.
https://www.chartjs.org/docs/latest/axes/radial/linear.html#point-label-options

Or maybe a new way to add labels to charts, similar to datalabels, but then always on the outside to label slices. Echarts for example supports these:
https://echarts.apache.org/examples/en/editor.html?c=pie-simple
https://echarts.apache.org/examples/en/editor.html?c=bar-polar-stack-radial

Workaround

Through this StackOverflow answer I found a workaround using the datalabels plugin. Simple example:
https://codepen.io/peteruithoven/pen/mdwxaMP?editors=0010
But this requires a plugin, manually increasing the padding, adjusting an offset through a onResize handler and calling this handler initially.

Simple example with default point labels:
https://codepen.io/peteruithoven/pen/LYLdMBE?editors=0010

@t-mangoe
Copy link
Contributor

I worked on this issue and tried implementing as a test.
How is this?

スクリーンショット 2021-11-20 9 22 30

@peteruithoven
Copy link
Author

That looks perfect 🤤

@kurkle
Copy link
Member

kurkle commented Nov 20, 2021

I think the option could be named offset as it's very similar to bar chart default index axis behavior.

@t-mangoe
Copy link
Contributor

I added code to automatically center the point labels when using a polar graph.
If it is ok, I am thinking adding tests and sending a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants