Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Pie chart offset not equal

Open adityagoel28 opened this issue 2 years ago • 6 comments

Expected behavior

Offset should be equal in all.

Current behavior

image

Pie chart offset between the slices is not equal, as shown in the image. Please tell how to resolve this.

Reproducible sample

None

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v3.7.1

Browser name and version

No response

Link to your project

No response

adityagoel28 avatar Apr 05 '22 19:04 adityagoel28

Can't seem to reproduce it, please add a reproducable sample as required by the issue template

LeeLenaleee avatar Apr 06 '22 06:04 LeeLenaleee

Here is the test case, as you can see the offsets are not equal. https://jsfiddle.net/b4Lynka9/

adityagoel28 avatar Apr 09 '22 13:04 adityagoel28

The offset is implemented as follows:

  1. Compute the angle in the middle of the arc segment
  2. Translate the arc along a line through that angle away from the center of the canvas by (offset / 2)

This implementation means that the space between arcs is not constant, nor is it designed to be. I'm not sure what to do here, but it seems like the spacing option might be the better one to use

etimberg avatar Apr 15 '22 22:04 etimberg

How do I implement equal spacing between the arcs, can you show an example please?

adityagoel28 avatar Apr 16 '22 05:04 adityagoel28

@etimberg I have the same need. A pie chart with all spacing equal. image

Is there any way to achieve that now?

ForeshadowRU avatar Oct 31 '22 09:10 ForeshadowRU

Hi @etimberg, I also have same need. We need the offset and hover offset when interacting with pie chart. spacing does work in our case.

image

DerrickWanglf avatar Dec 14 '22 06:12 DerrickWanglf

I was able to achieve something similar to equal spacing (works better for thinner doughnuts) by interlacing data values with the some fixed 'space' value (1 in my case) and interlacing colors with 'transparent' value. Here is the code: https://codepen.io/spagettiguru/pen/abjRqoM

Note that if you are using tooltips or labels you will have to make sure you don't show these for spacing arcs (tooltips are handled in the example).

spaghettiguru avatar Jan 31 '23 19:01 spaghettiguru

Same here

datasets: {
        doughnut: {
          borderWidth: 0,
          spacing: 2,
        },
      },
Screenshot 2023-08-31 at 10 29 22 am

jasperdunn avatar Aug 31 '23 00:08 jasperdunn