菜鸟学堂:
topn3dpie.aspx
------------------
<%@ page language="c#" codebehind="topn3dpie.aspx.cs" autoeventwireup="false" inherits="yeefly.topn3dpie" %>
topn3dpie.aspx.cs
-----------------
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.drawing.imaging;
using system.drawing.drawing2d;
using system.io;
namespace yeefly
{
/// <summary>
/// graph 的摘要说明。
/// </summary>
public class topn3dpie : system.web.ui.page
{
private void page_load(object sender, system.eventargs e)
{
response.contenttype = "image/jpeg";
const int width = 300, height = 300;
int x = 30, y = 50;
int piewidth = 120, pieheight = 40, pieshadow = 15;
int[] arrvote = {70,90,80,20,60,40};
random oran = new random();
bitmap objbitmap = new bitmap(width, height);
graphics objgraphics = graphics.fromimage(objbitmap);
objgraphics.drawrectangle(new pen(color.black),0,0,width,height);
objgraphics.fillrectangle(new solidbrush(color.white), 1, 1,width - 2, height - 2);
solidbrush objbrush = new solidbrush(color.blue);
objgraphics.smoothingmode = smoothingmode.antialias;
int icurrentpos = 0;
color[] arrcolor = {color.red,color.red,color.red,color.red,color.red,color.red};
for(int i = arrvote.length - 1 ; i >= 0; i--)
{
arrcolor[i] = color.fromargb(oran.next(255), oran.next(255), oran.next(255));
}
for(int i = arrvote.length - 1 ; i >= 0; i--)
{
objbrush.color = arrcolor[i];
for(int iloop2 = 0; iloop2 < pieshadow; iloop2++)
objgraphics.fillpie(new hatchbrush(hatchstyle.percent50,objbrush.color),x, y + iloop2, piewidth, pieheight, icurrentpos, arrvote[i]);
icurrentpos += arrvote[i];
}
icurrentpos = 0;
for(int i = arrvote.length - 1 ; i >= 0;i--)
{
objbrush.color = arrcolor[i];
objgraphics.fillpie(objbrush,x, y, piewidth, pieheight, icurrentpos, arrvote[i]);
icurrentpos += arrvote[i];
}
objbitmap.save(response.outputstream, imageformat.jpeg);
// clean up...
objgraphics.dispose();
objbitmap.dispose();
}
#region web 窗体设计器生成的代码
override protected void oninit(eventargs e)
{
//
// codegen: 该调用是 asp.net web 窗体设计器所必需的。
//
initializecomponent();
base.oninit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.load += new system.eventhandler(this.page_load);
}
#endregion
}
}