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 labels at start or end of arc instead of center #93

Open
Type1J opened this issue Oct 2, 2018 · 4 comments
Open

Pie chart labels at start or end of arc instead of center #93

Type1J opened this issue Oct 2, 2018 · 4 comments

Comments

@Type1J
Copy link

Type1J commented Oct 2, 2018

I'd like another parameter other than align and anchor to be used for label placement on pie/doughnut charts along the arc. I'm not sure what to call it, but arcPos might be good.

I'd like it to be a value between 0.0 and 1.0 where 0.0 is the beginning of the arc, and 1.0 is the end of the arc. The label placement for pie and doughnut charts currently is stuck at an arcPos of 0.5.

Even if you wanted to stick to the scheme of "begin", "center", or "end", I'd be fine with that, but having a value of 0.0 to 1.0 is more flexible.

@ministe2003
Copy link

I have this same problem using a doughnut extension as a gauge. For a gauge it doesn't make sense for the labels to be around the centre of the segments. If the labels could follow the direction of a segment that'd be great and we could have much more control over their position

@gretchenzuefeldt
Copy link

I know this is old but I thought I'd add this in case it helps anyone. I made this for myself so you might have to modify some stuff and I had trouble getting the code to format properly on here but here it is:

let numSectors = insert length of data array here; let sectorDegree = 180 / numSectors; let width = (canvas.parent().width() - parseInt(canvas.css('padding').replace("px","")*2)); let fontSize = 16; let b = (width/2)-3; let c = b-(fontSize*1.8); let a = Math.sqrt((Math.pow(b, 2) + Math.pow(c, 2)) - (2*b*c*Math.cos((sectorDegree/2) * Math.PI / 180))); let offset = a-(fontSize*1.2); let alignAngle = (Math.asin(Math.sin((sectorDegree/2) * Math.PI / 180)*c/a) * 180 / Math.PI)- (sectorDegree/2);

                         `   datalabels: {
                                        display: true,
                                        anchor: 'end',
                                        font: {
                                            size: fontSize,
                                        },
                                        offset: offset,
                                        align: function(context){
                                            return (sectorDegree * context.dataIndex) - alignAngle;
                                        },
                                }`

@aumartinez
Copy link

Hi it has been 3 years since this was suggested

@naomipol
Copy link

Take a look at my solution in stackoverflow:
https://stackoverflow.com/a/70322286/4610489

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

6 participants