Fixed DataLabels in Pie Chart ChartJS

Viewed 46

I am using ChartJS for my Lucky Spin Wheel, I have used Pie Chart to create wheel, Now I put datalabels according to requirement, and rotated that with following code

rotation: function(ctx) {
   const valuesBefore = ctx.dataset.data.slice(0, ctx.dataIndex).reduce((a, b) => a + b, 0);
   const sum = ctx.dataset.data.reduce((a, b) => a + b, 0);
   const rotation = ((valuesBefore + ctx.dataset.data[ctx.dataIndex] /2) /sum *360);
   return rotation < 180 ? rotation-90 : rotation+90;
}

They are coming as expected, But when I spin the wheel with

myChart.options.rotation = myChart.options.rotation + resultValue;
myChart.update()

Here resultValue is fixed 101, and after spinning the datalabels position also changed and not as expected, following are the images

Wheel Before Spin

Wheel after spin

Is there any way we can restrict datalables rotation?

0 Answers
Related