Giter VIP home page Giter VIP logo

Comments (13)

tchapi avatar tchapi commented on May 18, 2024 6

👍 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

from chartjs-plugin-datalabels.

tchapi avatar tchapi commented on May 18, 2024 5

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.

from chartjs-plugin-datalabels.

MikeBishop avatar MikeBishop commented on May 18, 2024 2

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.

from chartjs-plugin-datalabels.

HariPadBharti avatar HariPadBharti commented on May 18, 2024 1

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

from chartjs-plugin-datalabels.

AlbertoMontalesi avatar AlbertoMontalesi commented on May 18, 2024 1

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,
			}

from chartjs-plugin-datalabels.

simonbrunel avatar simonbrunel commented on May 18, 2024

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?

from chartjs-plugin-datalabels.

nickasd avatar nickasd commented on May 18, 2024

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.

from chartjs-plugin-datalabels.

nickasd avatar nickasd commented on May 18, 2024

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.

from chartjs-plugin-datalabels.

simonbrunel avatar simonbrunel commented on May 18, 2024

@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)?

from chartjs-plugin-datalabels.

theomarme avatar theomarme commented on May 18, 2024

Hi, i have same problem, still no solution ?

from chartjs-plugin-datalabels.

Herz3h avatar Herz3h commented on May 18, 2024

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 ?

from chartjs-plugin-datalabels.

kprkumar avatar kprkumar commented on May 18, 2024

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

from chartjs-plugin-datalabels.

emit077 avatar emit077 commented on May 18, 2024

try this one
https://stackoverflow.com/a/72731158/10175889
jsfiddle

from chartjs-plugin-datalabels.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.