1. generate a common pie chart.
Using System;
Using System. Collections. Generic;
Using System. Drawing;
Using System. Drawing. Imaging;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Public partial class Drawing: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Int [] data ={ 100,200,300,460 };
Color [] colors = {Color. Green, Color. Blue, Color. Yellow, Color. Tomato };
Bitmap bm = new Bitmap (400,400 );
Graphics g = Graphics. FromImage (bm );
G. Clear (Color. White );
G. DrawString ("pie chart test", new Font ("", 16), Brushes. Red, new PointF (5, 5 ));
Float totalValue = 0;
Foreach (int I in data)
{
TotalValue + = I;
}
Float sweepAngle = 0;
Float startAngle = 0;
Int index = 0;
Float x = 50f;
Float y = 50f;
Float width = 200f;
Foreach (int I in data)
{
SweepAngle = I/totalValue * 360;
G. FillPie (new SolidBrush (colors [index ++]), x, y, width, width, startAngle, sweepAngle );
StartAngle + = sweepAngle;
}
Bm. Save (Response. OutputStream, ImageFormat. Jpeg );
G. Dispose ();
}
}
2. If the pie chart needs to add edge lines, add the following code under the above red code: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + fingerprint + 1MvQ0L3hufvI58/czbyjuw.vcd4kpha + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140310/20140310091802189.jpg" alt = "">