Recently, on the mobile history phone bill page, a new pie chart with a small consumption proportion is added, which makes a little trouble for me to modify the bill page, if I want to modify the amount in my bill, I have to re-calculate the consumption proportion in Photoshop and then modify a New Graph Based on this, which is very troublesome. Therefore, I tried to draw such a "small circle cake" with the code exactly like its style ". Fortunately, this pie is relatively simple, and it is fixed by three parts of the fee, as shown in.
Although this chart is relatively simple, there are all the "troublesome" elements for creating a pie chart:
(1) angle conversion problem. A pie chart is not a forward view, but a skewed view. The pie chart and the video line have an angle of inclination. Therefore, we simply assume that the point on the edge of the pie will not change with the center of the pie as the origin, y has the following transformation relationship: y '= y * k; k = elliptical height/elliptical width, as shown in:
Therefore, tg a' = k tg a, that is, A' = atan (k * tg );
Note that the angle on the graph starts from 12 points. Therefore, the angle value of the round cake boundary Ray ranges from-90 ~ 270 degrees, while the arc tangent function value range is-90 ~ 90 degrees. After arc tangent, You need to remap the value to-90 ~ The value range is 270 degrees.
(2) Another difficulty is to draw the sides of the pie, that is, the cylindrical surface visible in the angle of view. Each side is a closed path composed of two vertical lines on both sides of the oval Arc Section and two vertical lines on both sides, then fill it in. For more information, see the DrawPieSide method. The code is omitted.
In this way, fill in the corresponding amount, click the generate button to generate a pie chart, and then click the Save button to save the image to the hard disk.
Source code download link:
Http://files.cnblogs.com/hoodlum1980/JRL_PieGraph.rar