File talk:Nibelle - Composition de la population.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

This file shows one of many possibilities to draw a pie chart.
First the largest percentage is drawn and gets an id.
It has no color, "fill" is neither "none" nor anythng else; its color definition has to be global at the <svg statement.
The smaller percentages are rotated by their angle, in this case 4% is 14.4°, 20% is 72°, 36% is 129.6° and 40% is 144°. The last rotation is for the largest percentage, in this case the 40%.
All rotated sectors are filled with their color. This way each new rotated sector overlays previous sectors until all sectors are at their position.

The largest sector is the only one who needs an exact calculation, in this case the sinus and cosinus of (144-90)° multiplied by the radius.
All other placements are done with the rotations by their angles.

This is a very easy way to draw a very exact pie chart; normally the first sector is defined with the global color at its place, and all the others get their color and are rotated to their position.