Hi I am trying to create a simple pie chart using the HTML canvas element. I found a nice tutorial on the web and starting to learn how it is done.
Now I want to add some text and since I am pretty retarded at math/geometry I need to know how to find the center of each slice in the pie where the text can be added.
Here is the loop code:
for ( i = 0; i < t.data.length; i++ )
{
label = t.data[i].label;
value = t.data[i].value;
color = t.data[i].color;
ctx.lineWidth = t.strokeLineWidth;
ctx.strokeStyle = "#FFFFFF";
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo( centerX, centerY );
ctx.arc( centerX, centerY, radius, lastEnd, lastEnd + ( Math.PI * 2 * ( value / total ) ), false );
ctx.lineTo( centerX, centerY );
ctx.fill();
ctx.stroke();
lastEnd += Math.PI * 2 * ( value / total );
}
Thanks in advance for sugestions and answers Kai