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

Pie chart offset not equal #10286

Open
adityagoel28 opened this issue Apr 5, 2022 · 11 comments
Open

Pie chart offset not equal #10286

adityagoel28 opened this issue Apr 5, 2022 · 11 comments

Comments

@adityagoel28
Copy link

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

@LeeLenaleee
Copy link
Collaborator

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

@adityagoel28
Copy link
Author

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

@etimberg
Copy link
Member

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

@adityagoel28
Copy link
Author

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

@ForeshadowRU
Copy link

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

Is there any way to achieve that now?

@DerrickWanglf
Copy link

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

@spaghettiguru
Copy link

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).

@jasperdunn
Copy link

Same here

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

@IdoBK
Copy link

IdoBK commented Jan 30, 2024

Hey, any update on this? Experiencing the same issue

datasets: [
      {
        data: dataAsPercentages.map(({ value }) => value),
        backgroundColor: dataAsPercentages.map(({ asset_type }) => ASSET_TYPE_TO_COLOR[asset_type]),
        spacing: 5,
        borderRadius: 0,
        borderWidth: 0,
      },
    ]

image

@vamshinenu
Copy link

looks like this issue is still open.

@TimChinye
Copy link

TimChinye commented May 2, 2024

+1 Really would like a fix to this, seems like a no-brainer...

@spaghettiguru's solution works but is certainly a workaround to an issue.

To add to their solution though, you can dynamically interlace 1 and 'transparent' using:
<Array>.flatMap(num => [1, num]) and <Array>.flatMap(color => ['transparent', color])

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