ASP.Net页面生成饼图的方法-创新互联

本篇内容主要讲解“ASP.Net页面生成饼图的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“ASP.Net页面生成饼图的方法”吧!

网站的建设创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为餐厅设计等企业提供专业服务。

1.生成普通饼图:


复制代码 代码如下:

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("饼图测试",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);
//g.DrawPie(Pens.Black,x,y,width,width,startAngle,sweepAngle); //加边线代码
startAngle += sweepAngle;
}
bm.Save(Response.OutputStream,ImageFormat.Jpeg);
g.Dispose();
}
}

运行效果如下图所示:

ASP.Net页面生成饼图的方法

2.如果饼图要加边线,就将上面代码中加注释的代码部分取消注释,如下代码所示:


复制代码 代码如下:

g.DrawPie(Pens.Black,x,y,width,width,startAngle,sweepAngle);

运行结果如下图:

ASP.Net页面生成饼图的方法

到此,相信大家对“ASP.Net页面生成饼图的方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联建站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


文章名称:ASP.Net页面生成饼图的方法-创新互联
转载来源:http://myzitong.com/article/dgjidg.html