Anyone able to solve this issue? I can draw the circle based on the functions we are using but I can’t seem to figure out how to dynamically set the labels in the center of the arc.

///Functions:

function polarToCartesian(centerX, centerY, radius, angleInDegrees){

var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;

return {x: centerX + (radius * Math.cos(angleInRadians)),

y: centerY + (radius * Math.sin(angleInRadians)) };}

function describeArc(x, y, radius, startAngle, endAngle){

var endAngleOriginal = endAngle;

if(endAngleOriginal - startAngle === 360){endAngle = 359; }

var start = polarToCartesian(x, y, radius, endAngle);

var end = polarToCartesian(x, y, radius, startAngle);

var arcSweep = endAngle - startAngle <= 180 ? “0” : “1”;

if(endAngleOriginal - startAngle === 360){

var d = [

“M”, start.x, start.y,

“A”, radius, radius, 0, arcSweep, 0, end.x, end.y, “z”

].join(" “);

}

else{

var d = [

“M”, start.x, start.y,

“A”, radius, radius, 0, arcSweep, 0, end.x, end.y

].join(” ");

}

```
return d ;
```

}

function between(x,a, b) {

return (x >= a && x <=b);

}

function setLabel(label, top, left){

```
query('#'+ label).attr('anchor','');
query('#'+ label).css('position','absolute');
query('#'+ label).css('left',Number(left) + "px");
query('#'+ label).css('top',Number(top) +"px");
```

}

var Total =Number(r.SXPRIN01) + Number(r.SXINTR01) + Number(r.SXESCP) + Number(r.SXOTHP) ;

var Prin =Number((Number(r.SXPRIN01)/Total) * 360);

var Int =Number((Number(r.SXINTR01)/Total) * 360);

var Esc =Number((Number(r.SXESCP)/Total) * 360);

var Oth=Number((Number(r.SXOTHP)/Total) * 360);

/* Examples on setting the values…

Total =360;

Prin =90;

Int =90;

Esc =90;

Oth =90;

*/

query(“#donutChart #arc1”).attr(“d”, describeArc(180, 120, 80, 0, Prin));

query(“#donutChart #arc2”).attr(“d”, describeArc(180, 120, 80, Prin, (Prin + Int)));

query(“#donutChart #arc3”).attr(“d”, describeArc(180, 120, 80, (Prin + Int), (Prin + Int + Esc)));

query(“#donutChart #arc4”).attr(“d”, describeArc(180, 120, 80, (Prin + Int + Esc), Prin + Int + Esc + Oth));

How to go about setting the labels dynamically ?

Example of hard coded label setting

setLabel(‘label1’,50,275);