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

Overlapping labels in pie chart #49

Open
nickasd opened this issue Apr 9, 2018 · 13 comments
Open

Overlapping labels in pie chart #49

nickasd opened this issue Apr 9, 2018 · 13 comments

Comments

@nickasd
Copy link

nickasd commented Apr 9, 2018

Are there any plans to improve the display of labels in pie charts? Currently I have situations like this:

bildschirmfoto 2018-04-09 um 13 01 02

I'm not sure what is the best way to solve it, perhaps adding a minimal y-offset to each label until each one is visible?

@simonbrunel
Copy link
Member

I think there are many ways to layout labels that overlap and ideally all should be supported since it impacts the UI. Can you draft your expectations in this case?

@nickasd
Copy link
Author

nickasd commented Apr 20, 2018

Thanks for answering! Well, I don't have any particular expectations, but one idea might be: since only two labels can be placed at the exact same y-position, they could be have some x-offset until they no more overlap. Then there could still be slight overlaps on the y-axis, but unless the font is automatically adjusted down to make them fit, I guess one would have to come up with some algorithm to calculate the optimal y-offsets.

@nickasd
Copy link
Author

nickasd commented May 11, 2018

Also it would be nice if long labels wouldn't simply be cut off at the edges of the canvas, but instead they would be pushed inwards until they are entirely visible.

@simonbrunel simonbrunel mentioned this issue Jul 5, 2018
@tchapi
Copy link

tchapi commented Jul 5, 2018

👍 on this. Similarly when the underlying data is "small" (as in : produces a very small pie slice), the problem is there too :

screen shot 2018-07-05 at 16 19 07

To date is there any workaround that can be implemented easily using the public API ?

Thanks a lot for this plugin btw

@simonbrunel
Copy link
Member

@tchapi sorry for the late answer: no, there is no public API to implement this kind of feature. But I'm currently looking to introduce a new option to prevent overlapping labels. What would be the expected result in your case (screenshot you posted)?

@tchapi
Copy link

tchapi commented Nov 15, 2018

Hi @simonbrunel and thanks for taking the time to look into this. I think the best behaviour would be to offset one or several labels when they are overlapping, adding a line to the relevant segment.

The offset would be chart-type-dependant, since it should be calculated differently if it's a pie chart (angular offset) vs. a bar chart (linear offset along one of the axis).

Something like this (in red) in my example :

screen shot 2018-11-15 at 10 17 43

But TBH, any solution that makes the labels readable would be a great plus anyway.

@theomarme
Copy link

Hi, i have same problem, still no solution ?

@HariPadBharti
Copy link

try referring https://stackoverflow.com/questions/45352194/chart-js-v2-6-add-arrows-to-pie-chart-output-values?answertab=active#tab-top

@AlbertoMontalesi
Copy link

Try this

set the position to outside and give it a margin, it won't fix it 100% but it should help make it more readable

	labels: {
				position: 'outside',
				textMargin: 10,
			}

@Herz3h
Copy link

Herz3h commented Aug 13, 2019

I kind of manage to avoid the overlap by using:

datalabels: {
anchor: 'end',
align: 'end',
offset: 10
}

But then the labels are drawn hidden outside the parent div, and are therefore hidden sometimes. Is there any way to adjust the margin of the chart accordingly so everything is visibile ?

@MikeBishop
Copy link

The newer options to avoid overlap work, but the "auto" behavior to prioritize the earlier element in the series isn't always ideal. Personally, I'd rather see a policy of prioritizing the larger value, at least for a pie chart. Perhaps more flexible would be the ability to define a function that gets passed collections of labels that overlap and returns the one to show.

@kprkumar
Copy link

I need to add data labels outside the pie chart with link to it. Is it possible using chartJs.

@emit077
Copy link

emit077 commented Jun 23, 2022

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

No branches or pull requests

10 participants