代码
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();
}

 

相关文章:

  • 2021-11-23
  • 2021-11-14
  • 2021-10-03
  • 2022-02-09
  • 2022-02-02
  • 2021-05-17
猜你喜欢
  • 2021-11-24
  • 2021-11-10
  • 2022-01-16
  • 2022-01-07
  • 2021-12-09
相关资源
相似解决方案