You can use the following equations to calculate a point around the circumference of a circle:
x = cx + r * cos(a) y = cy + r * sin(a)
Where (cx, cy) is the center of the circle, r is the radius, and a is the angle.
For this to work for you, you will need a way to calculate the angle based on the pieces of cake on your chart - see below.
According to the d3 documentation for the pie layout, the pie function returns a list of arcs, so you can process this data to calculate each of its points:
pie (values [, index])
Computes the pie function for the specified array of values. An optional index can be specified, which is passed as a function of the beginning and end of the corner. The return value is an array of arc descriptors.
- value - the data value returned by the value attribute.
- startAngle - the starting angle of the arc in radians.
- endAngle - the end angle of the arc in radians.
- is the source date for this arc.
Presumably you can just take half the distance between endAngle and startAngle for each arc and put your point there.
For what it's worth, here is the code from pie.js , which is used to calculate each arc:
Does it help?
Justin ethier
source share