ASP.Net页面生成饼图实例
本文实例讲述了asp.net页面生成饼图的方法。分享给大家供大家参考。具体实现方法如下:
1.生成普通饼图:
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();
}
}
运行效果如下图所示:
2.如果饼图要加边线,就将上面代码中加注释的代码部分取消注释,如下代码所示:
运行结果如下图:
希望本文所述对大家的asp.net程序设计有所帮助。