![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
protected
void
Page_Load(
object
sender, EventArgs e)
{
int [] data = { 100 , 200 , 300 , 400 , 66 , 55 , 777 , 435 , 634 , 454 , 634 , 443 , 352 , 546 , 635 , 454 , 454 , 5 , 535 , };
// 饼的颜色
Color[] colors = { Color.Red, Color.LightCoral, Color.LightCyan, Color.LightGray, Color.LightGreen, Color.LightPink, Color.LightSeaGreen };
// 要绘制的对象
Bitmap bm = new Bitmap( 400 , 400 );
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.Silver);
g.DrawString( " 饼图测试 " , new Font( " 宋体 " , 16 ), Brushes.Red, new PointF( 4 , 4 ));
float totalValue = 0 ;
foreach ( float i in data)
{
totalValue += i;
}
float sweepAngle = 0 ; // 本次经过角度
float startAngle = 0 ; // 本次起始角度
float x = 50f; // 饼所在的矩形方位。
float y = 50f;
float width = 300 ;
for ( int i = 0 ;i < data.Length;i ++ )
{
sweepAngle = data[i] / totalValue * 360 ;
//
g.FillPie( new SolidBrush(colors[i % colors.Length]), x, y, width, width, startAngle, sweepAngle);
g.DrawPie(Pens.Indigo, x, y, width, width, startAngle, sweepAngle);
startAngle += sweepAngle;
}
// 图形输出方式
bm.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
}
{
int [] data = { 100 , 200 , 300 , 400 , 66 , 55 , 777 , 435 , 634 , 454 , 634 , 443 , 352 , 546 , 635 , 454 , 454 , 5 , 535 , };
// 饼的颜色
Color[] colors = { Color.Red, Color.LightCoral, Color.LightCyan, Color.LightGray, Color.LightGreen, Color.LightPink, Color.LightSeaGreen };
// 要绘制的对象
Bitmap bm = new Bitmap( 400 , 400 );
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.Silver);
g.DrawString( " 饼图测试 " , new Font( " 宋体 " , 16 ), Brushes.Red, new PointF( 4 , 4 ));
float totalValue = 0 ;
foreach ( float i in data)
{
totalValue += i;
}
float sweepAngle = 0 ; // 本次经过角度
float startAngle = 0 ; // 本次起始角度
float x = 50f; // 饼所在的矩形方位。
float y = 50f;
float width = 300 ;
for ( int i = 0 ;i < data.Length;i ++ )
{
sweepAngle = data[i] / totalValue * 360 ;
//
g.FillPie( new SolidBrush(colors[i % colors.Length]), x, y, width, width, startAngle, sweepAngle);
g.DrawPie(Pens.Indigo, x, y, width, width, startAngle, sweepAngle);
startAngle += sweepAngle;
}
// 图形输出方式
bm.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
}