Gho5t
Gho5t

Reputation: 1060

Raphael JS Pie Chart Labels

I need to have labels on my pie chart and I am looking at the example of the pie chart: http://raphaeljs.com/pie.html.

In my implementation and on the example, the labels are not consistently the same distance away from the pie chart. Is there something wrong with the math used? It doesn't really make sense to me.

txt = paper.text(cx + (r + delta + 55) * Math.cos(-popangle * rad), cy + (r + delta + 25) * Math.sin(-popangle * rad), labels[j])

(Taken from http://raphaeljs.com/pie.js)

Upvotes: 2

Views: 1726

Answers (1)

Paul Rosenzweig
Paul Rosenzweig

Reputation: 21

The example's labels aren't always the same distance from the pie. Compare the "Objective-C" and "Java" labels. This effect is more pronounced with longer labels. Raphael defaults to text-anchor="middle".

If you wanted the closest point on the label to be a constant distance from the pie, the math would get much uglier. You'd need to calculate which side of the pie the label is on and adjust the text-anchor accordingly.

Upvotes: 1

Related Questions