using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ZedGraph;
using ZedGraph.Web;
using System.Drawing;

public partial class _Default : System.Web.UI.Page


{
string typesign = "";
protected void Page_Load(object sender, EventArgs e)

{
this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph);//注册事件
typesign = "line";
}
// Call this method from the Form_Load method, passing your ZedGraphControl

private void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)

{
// 初始化画图面版
GraphPane myPane = masterPane[0];
if (typesign == "bar")

{

// 画图面版标题
myPane.Title.Text = "收入统计";
// 画图面版X标题
myPane.XAxis.Title.Text = "区域";

//初始化数据
PointPairList list = new PointPairList();
PointPairList list2 = new PointPairList();
PointPairList list3 = new PointPairList();
Random rand = new Random();
double total = 0;
for (double x = 0; x < 5; x += 1.0)

{
double y = rand.NextDouble() * 100;
double y2 = rand.NextDouble() * 100;
double y3 = rand.NextDouble() * 100;
list.Add(x, y);
list2.Add(x, y2);
list3.Add(x, y3);

total += y;
}

// 画图面版Y标题
myPane.YAxis.Title.Text = "销售总额:" + total.ToString("F") + " 元";
//柱的画笔
// public BarItem AddBar(string 名称, IPointList 数据, Color 颜色);
BarItem myCurve = myPane.AddBar("收入", list, Color.Blue);
myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue);
BarItem myCurve2 = myPane.AddBar("买农药", list2, Color.Red);
myCurve2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
BarItem myCurve3 = myPane.AddBar("买化肥", list3, Color.Green);
myCurve3.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green);

myPane.XAxis.MajorTic.IsBetweenLabels = true;
//XAxis标注

string[] labels =
{ "橘子", "西瓜", "梨", "桃子", "枣子" };
myPane.XAxis.Scale.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text;
//图区以外的颜色
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
//背景颜色
myPane.Chart.Fill = new Fill(Color.Red, Color.LightGoldenrodYellow, 45.0f);
masterPane.AxisChange(g);

}
else if (typesign == "pie")

{

// 设置画版区的标题
myPane.Title.Text = "2007 fruit Sales\n($M)";//\n:换行
//文字是否斜体
myPane.Title.FontSpec.IsItalic = true;
//字体大小
myPane.Title.FontSpec.Size = 24f;
//字体
myPane.Title.FontSpec.Family = "Times New Roman";

// 填充Pane背景颜色和倾斜度
myPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
// 背景填充类型
myPane.Chart.Fill.Type = FillType.None;

// 设置location
myPane.Legend.Position = LegendPos.Float;
myPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction,
AlignH.Right, AlignV.Top);
//slices文字大小
myPane.Legend.FontSpec.Size = 10f;
myPane.Legend.IsHStack = false;

// 添加一切片值
// public PieItem AddPieSlice(double 数据, Color 大圆里的该切片颜色, Color 大圆里的该切片颜色, float fillAngle, double displacement, string label);
PieItem segment1 = myPane.AddPieSlice(20, Color.Navy, Color.White, 45f, 0, "橘子");
PieItem segment3 = myPane.AddPieSlice(30, Color.Purple, Color.White, 45f, .0, "西瓜");
PieItem segment4 = myPane.AddPieSlice(10.21, Color.LimeGreen, Color.White, 45f, 0, "梨");
PieItem segment2 = myPane.AddPieSlice(40, Color.SandyBrown, Color.White, 45f, 0.2, "桃子");
PieItem segment6 = myPane.AddPieSlice(250, Color.Red, Color.White, 45f, 0, "枣子");
PieItem segment7 = myPane.AddPieSlice(50, Color.Blue, Color.White, 45f, 0.2, "蔬菜");
PieItem segment8 = myPane.AddPieSlice(400, Color.Green, Color.White, 45f, 0, "玉米");
PieItem segment9 = myPane.AddPieSlice(50, Color.Yellow, Color.White, 45f, 0.2, "地瓜");
//标签背景颜色
segment2.LabelDetail.FontSpec.FontColor = Color.Red;

// 总额
CurveList curves = myPane.CurveList;
double total = 0;
for (int x = 0; x < curves.Count; x++)
total += ((PieItem)curves[x]).Value;

// 给Total赋值
TextObj text = new TextObj("Total 2004 Sales\n" + "$" + total.ToString() + "M",
0.18F, 0.40F, CoordType.PaneFraction);
//text的Location设置
text.Location.AlignH = AlignH.Center;
text.Location.AlignV = AlignV.Bottom;
//是否有边框
text.FontSpec.Border.IsVisible = false;
//区域的背景色
text.FontSpec.Fill = new Fill(Color.White, Color.FromArgb(255, 100, 100), 45F);
text.FontSpec.StringAlignment = StringAlignment.Center;
myPane.GraphObjList.Add(text);

// 创建一个阴影区域,看起来有渐变
TextObj text2 = new TextObj(text);
//背景色
text2.FontSpec.Fill = new Fill(Color.Black);
//text2.Location
text2.Location.X += 0.008f;
text2.Location.Y += 0.01f;
myPane.GraphObjList.Add(text2);
masterPane.AxisChange(g);
}
else if (typesign == "line")

{
//设置标题和x,y坐标的文字
myPane.Title.Text = "Line Graph with Band Demo";
myPane.XAxis.Title.Text = "Sequence";
myPane.YAxis.Title.Text = "Temperature, C";

// 设置初始数据

double[] y =
{ 100, 115, 75, 22, 98, 40, 10 };

double[] y2 =
{ 90, 100, 95, 35, 80, 35, 35 };

double[] y3 =
{ 80, 110, 65, 15, 54, 67, 18 };

double[] x =
{ 100, 200, 300, 400, 500, 600, 700 };

// 填充axis背景颜色和倾斜度
myPane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F);


//创建一条红色的线Curve 1
LineItem myCurve = myPane.AddCurve("收入", x, y, Color.Red);
//用红色填充,使符号不透明(可以填充你需要的颜色)
myCurve.Symbol.Fill = new Fill(Color.Red);

// 创建一条Blue色的线Curve 2,"Curve2",你可以改变名称
myCurve = myPane.AddCurve("成本 ", x, y2, Color.Blue);
// Make the symbols opaque by filling them with white
myCurve.Symbol.Fill = new Fill(Color.White);

// 创建一条Green色的线Curve 3,"Curve3",你可以改变名称
myCurve = myPane.AddCurve("时间", x, y3, Color.Green);
// Make the symbols opaque by filling them with white
myCurve.Symbol.Fill = new Fill(Color.White);


//手动设置x axis范围
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 800;
// 显示 the Y axis格子线
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
// 显示 the X axis格子线
// myPane.XAxis.MinorGrid.IsVisible = true;
// myPane.XAxis.MinorGrid.IsVisible = true;

//添加一栏加亮显示区域
//x为基准,y为box的上线,width为box的width,height为box的height,borderColor为边界颜色,fillColor为box的填充颜色
//public BoxObj(double x, double y, double width, double height, Color borderColor, Color fillColor);
BoxObj box = new BoxObj(0, 100, 800, 30, Color.Empty,
Color.FromArgb(150, Color.LightGreen));
box.Fill = new Fill(Color.White, Color.FromArgb(200, Color.LightGreen), 45.0F);
//使用BehindGrid区域,把加加亮显示区域叠在lines之下
box.ZOrder = ZOrder.F_BehindGrid;
myPane.GraphObjList.Add(box);

//添加文本到加亮区域,并对其进行设置(text:要显示的文本,以那为基准(x,y),coordType为什么类型,AlignV设置左右对齐方式,AlignV设置上下对齐方式)
// public TextObj(string text, double x, double y, CoordType coordType, AlignH alignH, AlignV alignV);
TextObj text = new TextObj("基准线", 750, 85, CoordType.AxisXYScale,
AlignH.Right, AlignV.Center);
//是否有背景
text.FontSpec.Fill.IsVisible = false;
//是否有边框
text.FontSpec.Border.IsVisible = false;
//文字是否粗体
text.FontSpec.IsBold = true;
//文字是否斜体
text.FontSpec.IsItalic = true;
//填充
myPane.GraphObjList.Add(text);

}
//保存位置
// ZedGraphWeb1.RenderedImagePath = "~/Image/";
}


}

前台拖拽zeweb
posted on
2008-06-11 09:19
code life
阅读(
1003)
评论()
收藏
举报