The example in this article describes how the ASP.net page generates pie charts. Share to everyone for your reference. The implementation methods are as follows:
1. Generate Ordinary Pie chart:
Copy Code code as follows:
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 ("XXFarEastFont-Arial"), 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);
G.drawpie (Pens.black,x,y,width,width,startangle,sweepangle); Edge Code
StartAngle + = Sweepangle;
}
Bm. Save (Response.outputstream,imageformat.jpeg);
G.dispose ();
}
}
The effect is as shown in the following illustration:
2. If the pie chart is to be added to the sideline, uncomment the code section above, as shown in the following code:
Copy Code code as follows:
G.drawpie (Pens.black,x,y,width,width,startangle,sweepangle);
The results of the operation are shown below:
I hope this article will help you with the ASP.net program design.