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; //添加 Imaging 的引用。
namespace fund
{
///<summary>
/// ChartText 的摘要说明。
/// 作者:Shadow
///</summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Bitmap objBitMap = new Bitmap(400, 240);
Graphics objGraphics;
objGraphics = Graphics.FromImage(objBitMap);
objGraphics.Clear(Color.White);
int[] arrValues = {40000,32000,24000,30000,36000,28000};
string[] arrValueNames = new string[]{"第一次","第二次","第三次","第四次","第五次","第六次"};
objGraphics.DrawString(" 山东鲁能主场球迷人数统计(人)",
new Font("宋体", 16), Brushes.Blue, new PointF(5, 5));
PointF symbolLeg = new PointF(335, 20);
PointF descLeg = new PointF(360, 16);
//画出说明部分的图形
for (int i = 0; i < arrValueNames.Length; i++)
{
objGraphics.FillRectangle(new SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10);
objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10);
objGraphics.DrawString(arrValueNames[i].ToString(), new Font("宋体", 10), Brushes.Black, descLeg);
symbolLeg.Y += 15;
descLeg.Y += 15;
}
float TotalValues = 0;
for (int i = 0; i <= arrValues.Length - 1; i++)
{
TotalValues += arrValues[i];
}
//绘出矩形图。
float Rectangleheight = 0;
PointF recLeg = new PointF(12,200-arrValues[0]/TotalValues*300);
for (int i = 0; i < arrValues.Length; i++)
{
Rectangleheight = arrValues[i] / TotalValues *300;
objGraphics.FillRectangle(new SolidBrush(GetColor(i)), (i * 35) + 15, 200 - Rectangleheight, 20,
Rectangleheight + 50);
objGraphics.DrawRectangle(Pens.Black, (i * 35) + 15, 200 - Rectangleheight, 20, Rectangleheight + 50);
recLeg.Y=200-Rectangleheight-14;
objGraphics.DrawString(arrValues[i].ToString(), new Font("宋体", 10), Brushes.Blue, recLeg);
recLeg.X+=35;
}
//绘出圆形图。
float sglCurrentAngle = 0;
float sglTotalAngle = 0;
for (int i = 0; i < arrValues.Length; i++)
{
sglCurrentAngle = arrValues[i] / TotalValues * 360;
objGraphics.FillPie(new SolidBrush(GetColor(i)), 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle);
objGraphics.DrawPie(Pens.Black, 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle);
sglTotalAngle += sglCurrentAngle;
}
objBitMap.Save(Response.OutputStream, ImageFormat.Gif);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}