using ZedGraph

参考:http://zedgraph.org/wiki/index.php?title=Sample_Graphs效果如下:

  1using ZedGraph
  2using ZedGraphusing System;
  3using ZedGraphusing System.Collections;
  4using ZedGraphusing System.ComponentModel;
  5using ZedGraphusing System.Data;
  6using ZedGraphusing System.Drawing;
  7using ZedGraphusing System.Web;
  8using ZedGraphusing System.Web.SessionState;
  9using ZedGraphusing System.Web.UI;
 10using ZedGraphusing System.Web.UI.WebControls;
 11using ZedGraphusing System.Web.UI.HtmlControls;
 12using ZedGraphusing ZedGraph;
 13using ZedGraphusing ZedGraph.Web;
 14using ZedGraph
 15using ZedGraph     string typesign = "";        
 16using ZedGraph          private void Page_Load(object sender, System.EventArgs e)
 17using ZedGraphusing ZedGraph          using ZedGraph{
 18using ZedGraph              ZedGraphWeb1.OutputFormat = ZedGraphWeb.ZedGraphWebFormat.Gif;
 19using ZedGraph              typesign = Request.QueryString["typesign"];
 20using ZedGraph          }

 21using ZedGraph
 22using ZedGraphprivate void InitializeComponent()
 23using ZedGraphusing ZedGraph          using ZedGraph{
 24using ZedGraph              this.Load += new System.EventHandler(this.Page_Load);
 25using ZedGraph              this.ZedGraphWeb1.RenderGraph += new ZedGraphWebControlEventHandler(this.OnRenderGraph);
 26using ZedGraph
 27using ZedGraph          }

 28using ZedGraph
 29using ZedGraphprivate void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)
 30using ZedGraphusing ZedGraph          using ZedGraph{
 31using ZedGraph              // 初始化画图面版
 32using ZedGraph              GraphPane myPane = masterPane[0];       
 33using ZedGraph              if (typesign == "bar")
 34using ZedGraphusing ZedGraph              using ZedGraph{  
 35using ZedGraph               
 36using ZedGraph                  // 画图面版标题
 37using ZedGraph                  myPane.Title.Text = "收入统计";
 38using ZedGraph                  // 画图面版X标题
 39using ZedGraph                  myPane.XAxis.Title.Text = "区域";
 40using ZedGraph                
 41using ZedGraph                  //初始化数据
 42using ZedGraph                  PointPairList list = new PointPairList();
 43using ZedGraph                  PointPairList list2 = new PointPairList();
 44using ZedGraph                  PointPairList list3 = new PointPairList();
 45using ZedGraph                  Random rand = new Random();
 46using ZedGraph                  double total = 0;
 47using ZedGraph                  for (double x = 0; x < 5; x += 1.0)
 48using ZedGraphusing ZedGraph                  using ZedGraph{
 49using ZedGraph                      double y = rand.NextDouble() * 100;
 50using ZedGraph                      double y2 = rand.NextDouble() * 100;
 51using ZedGraph                      double y3 = rand.NextDouble() * 100;
 52using ZedGraph                      list.Add(x, y);
 53using ZedGraph                      list2.Add(x, y2);
 54using ZedGraph                      list3.Add(x, y3);
 55using ZedGraph                    
 56using ZedGraph                      total+=y;
 57using ZedGraph                  }
               
 58using ZedGraph               
 59using ZedGraph                  // 画图面版Y标题
 60using ZedGraph                  myPane.YAxis.Title.Text = "销售总额:"+total.ToString("F")+" 元";
 61using ZedGraph                  //柱的画笔
 62using ZedGraph                  //    public BarItem AddBar(string 名称, IPointList 数据, Color 颜色);
 63using ZedGraph                  BarItem myCurve = myPane.AddBar("收入", list, Color.Blue);
 64using ZedGraph                  myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue);
 65using ZedGraph                  BarItem myCurve2 = myPane.AddBar("买农药", list2, Color.Red);
 66using ZedGraph                  myCurve2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
 67using ZedGraph                  BarItem myCurve3 = myPane.AddBar("买化肥", list3, Color.Green);
 68using ZedGraph                  myCurve3.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green);
 69using ZedGraph
 70using ZedGraph                  myPane.XAxis.MajorTic.IsBetweenLabels = true;
 71using ZedGraph                  //XAxis标注
 72using ZedGraphusing ZedGraph                  string[] labels = using ZedGraph"橘子""西瓜""""桃子""枣子" };
 73using ZedGraph                  myPane.XAxis.Scale.TextLabels = labels;
 74using ZedGraph                  myPane.XAxis.Type = AxisType.Text;
 75using ZedGraph                  //图区以外的颜色
 76using ZedGraph                  myPane.Fill = new Fill(Color.White, Color.FromArgb(200200255), 45.0f);
 77using ZedGraph                  //背景颜色
 78using ZedGraph                  myPane.Chart.Fill = new Fill(Color.Red, Color.LightGoldenrodYellow, 45.0f);
 79using ZedGraph                  masterPane.AxisChange(g); 
 80using ZedGraph            
 81using ZedGraph              }

 82using ZedGraph              else if(typesign == "pie")
 83using ZedGraphusing ZedGraph              using ZedGraph{
 84using ZedGraph
 85using ZedGraph                  // 设置画版区的标题            
 86using ZedGraph                  myPane.Title.Text = "2007 fruit Sales\n($M)";//\n:换行
 87using ZedGraph                  //文字是否斜体
 88using ZedGraph                  myPane.Title.FontSpec.IsItalic = true;
 89using ZedGraph                  //字体大小
 90using ZedGraph                  myPane.Title.FontSpec.Size = 24f;
 91using ZedGraph                  //字体
 92using ZedGraph                  myPane.Title.FontSpec.Family = "Times New Roman";
 93using ZedGraph
 94using ZedGraph                  // 填充Pane背景颜色和倾斜度
 95using ZedGraph                  myPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
 96using ZedGraph                  // 背景填充类型
 97using ZedGraph                  myPane.Chart.Fill.Type = FillType.None;
 98using ZedGraph
 99using ZedGraph                  // 设置location
100using ZedGraph                  myPane.Legend.Position = LegendPos.Float;
101using ZedGraph                  myPane.Legend.Location = new Location(0.95f0.15f, CoordType.PaneFraction,
102using ZedGraph                                      AlignH.Right, AlignV.Top);
103using ZedGraph                  //slices文字大小
104using ZedGraph                  myPane.Legend.FontSpec.Size = 10f;
105using ZedGraph                  myPane.Legend.IsHStack = false;
106using ZedGraph
107using ZedGraph                  // 添加一切片值
108using ZedGraph                  // public PieItem AddPieSlice(double 数据, Color 大圆里的该切片颜色, Color 大圆里的该切片颜色, float fillAngle, double displacement, string label);
109using ZedGraph                  PieItem segment1 = myPane.AddPieSlice(20, Color.Navy, Color.White, 45f, 0"橘子");
110using ZedGraph                  PieItem segment3 = myPane.AddPieSlice(30, Color.Purple, Color.White, 45f, .0"西瓜");
111using ZedGraph                  PieItem segment4 = myPane.AddPieSlice(10.21, Color.LimeGreen, Color.White, 45f, 0"");
112using ZedGraph                  PieItem segment2 = myPane.AddPieSlice(40, Color.SandyBrown, Color.White, 45f, 0.2"桃子");
113using ZedGraph                  PieItem segment6 = myPane.AddPieSlice(250, Color.Red, Color.White, 45f, 0"枣子");
114using ZedGraph                  PieItem segment7 = myPane.AddPieSlice(50, Color.Blue, Color.White, 45f, 0.2"蔬菜");
115using ZedGraph                  PieItem segment8 = myPane.AddPieSlice(400, Color.Green, Color.White, 45f, 0"玉米");
116using ZedGraph                  PieItem segment9 = myPane.AddPieSlice(50, Color.Yellow, Color.White, 45f, 0.2"地瓜");
117using ZedGraph                  //标签背景颜色
118using ZedGraph                  segment2.LabelDetail.FontSpec.FontColor = Color.Red;
119using ZedGraph
120using ZedGraph                  // 总额                     
121using ZedGraph                  CurveList curves = myPane.CurveList;
122using ZedGraph                  double total = 0;
123using ZedGraph                  for (int x = 0; x < curves.Count; x++)
124using ZedGraph                      total += ((PieItem)curves[x]).Value;
125using ZedGraph
126using ZedGraph                  // 给Total赋值
127using ZedGraph                  TextObj text = new TextObj("Total 2004 Sales\n" + "$" + total.ToString() + "M",
128using ZedGraph                                      0.18F0.40F, CoordType.PaneFraction);
129using ZedGraph                  //text的Location设置
130using ZedGraph                  text.Location.AlignH = AlignH.Center;
131using ZedGraph                  text.Location.AlignV = AlignV.Bottom;
132using ZedGraph                  //是否有边框
133using ZedGraph                  text.FontSpec.Border.IsVisible = false;
134using ZedGraph                  //区域的背景色
135using ZedGraph                  text.FontSpec.Fill = new Fill(Color.White, Color.FromArgb(255100100), 45F);
136using ZedGraph                  text.FontSpec.StringAlignment = StringAlignment.Center;
137using ZedGraph                  myPane.GraphObjList.Add(text);
138using ZedGraph
139using ZedGraph                  // 创建一个阴影区域,看起来有渐变
140using ZedGraph                  TextObj text2 = new TextObj(text);
141using ZedGraph                  //背景色
142using ZedGraph                  text2.FontSpec.Fill = new Fill(Color.Black);
143using ZedGraph                  //text2.Location
144using ZedGraph                  text2.Location.X += 0.008f;
145using ZedGraph                  text2.Location.Y += 0.01f;
146using ZedGraph                  myPane.GraphObjList.Add(text2);
147using ZedGraph                  masterPane.AxisChange(g);
148using ZedGraph              }

149using ZedGraph              else if (typesign == "line")
150using ZedGraphusing ZedGraph              using ZedGraph{            
151using ZedGraph              //设置标题和x,y坐标的文字
152using ZedGraph     myPane.Title.Text = "Line Graph with Band Demo";
153using ZedGraph     myPane.XAxis.Title.Text = "Sequence";
154using ZedGraph     myPane.YAxis.Title.Text = "Temperature, C";
155using ZedGraph
156using ZedGraph              // 设置初始数据
157using ZedGraphusing ZedGraph     double[] y = using ZedGraph1001157522984010 };
158using ZedGraphusing ZedGraph     double[] y2 = using ZedGraph901009535803535 };
159using ZedGraphusing ZedGraph     double[] y3 = using ZedGraph801106515546718 };
160using ZedGraphusing ZedGraph     double[] x = using ZedGraph100200300400500600700 };
161using ZedGraph   
162using ZedGraph              // 填充axis背景颜色和倾斜度
163using ZedGraph     myPane.Chart.Fill = new Fill( Color.FromArgb( 255255245), Color.FromArgb( 255255190), 90F );
164using ZedGraph
165using ZedGraph
166using ZedGraph              //创建一条红色的线Curve 1
167using ZedGraph     LineItem myCurve = myPane.AddCurve( "收入", x, y, Color.Red );
168using ZedGraph              //用红色填充,使符号不透明(可以填充你需要的颜色)  
169using ZedGraph     myCurve.Symbol.Fill = new Fill( Color.Red);
170using ZedGraph
171using ZedGraph              // 创建一条Blue色的线Curve 2,"Curve2",你可以改变名称
172using ZedGraph     myCurve = myPane.AddCurve( "成本 ", x, y2, Color.Blue );
173using ZedGraph     // Make the symbols opaque by filling them with white
174using ZedGraph     myCurve.Symbol.Fill = new Fill( Color.White );
175using ZedGraph
176using ZedGraph              // 创建一条Green色的线Curve 3,"Curve3",你可以改变名称
177using ZedGraph     myCurve = myPane.AddCurve( "时间", x, y3, Color.Green );
178using ZedGraph     // Make the symbols opaque by filling them with white
179using ZedGraph     myCurve.Symbol.Fill = new Fill( Color.White );
180using ZedGraph
181using ZedGraph  
182using ZedGraph              //手动设置x axis范围
183using ZedGraph     myPane.XAxis.Scale.Min = 0;
184using ZedGraph     myPane.XAxis.Scale.Max = 800;
185using ZedGraph     // 显示 the Y axis格子线
186using ZedGraph     myPane.YAxis.MajorGrid.IsVisible = true;
187using ZedGraph     myPane.YAxis.MinorGrid.IsVisible = true;
188using ZedGraph              // 显示 the X axis格子线
189using ZedGraph             // myPane.XAxis.MinorGrid.IsVisible = true;
190using ZedGraph             // myPane.XAxis.MinorGrid.IsVisible = true;
191using ZedGraph           
192using ZedGraph              //添加一栏加亮显示区域 
193using ZedGraph              //x为基准,y为box的上线,width为box的width,height为box的height,borderColor为边界颜色,fillColor为box的填充颜色
194using ZedGraph           //public BoxObj(double x, double y, double width, double height, Color borderColor, Color fillColor);
195using ZedGraph     BoxObj box = new BoxObj( 010080030, Color.Empty, 
196using ZedGraph       Color.FromArgb( 150, Color.LightGreen ) );
197using ZedGraph     box.Fill = new Fill( Color.White, Color.FromArgb( 200, Color.LightGreen ), 45.0F );
198using ZedGraph              //使用BehindGrid区域,把加加亮显示区域叠在lines之下   
199using ZedGraph     box.ZOrder = ZOrder.F_BehindGrid;
200using ZedGraph     myPane.GraphObjList.Add( box );
201using ZedGraph
202using ZedGraph              //添加文本到加亮区域,并对其进行设置(text:要显示的文本,以那为基准(x,y),coordType为什么类型,AlignV设置左右对齐方式,AlignV设置上下对齐方式)
203using ZedGraph              // public TextObj(string text, double x, double y, CoordType coordType, AlignH alignH, AlignV alignV);
204using ZedGraph     TextObj text = new TextObj( "基准线"75085, CoordType.AxisXYScale,
205using ZedGraph           AlignH.Right, AlignV.Center );
206using ZedGraph              //是否有背景
207using ZedGraph              text.FontSpec.Fill.IsVisible = false;
208using ZedGraph              //是否有边框
209using ZedGraph              text.FontSpec.Border.IsVisible = false;
210using ZedGraph              //文字是否粗体
211using ZedGraph     text.FontSpec.IsBold = true;
212using ZedGraph              //文字是否斜体
213using ZedGraph     text.FontSpec.IsItalic = true;
214using ZedGraph              //填充
215using ZedGraph     myPane.GraphObjList.Add( text );
216using ZedGraph
217using ZedGraph              }

218using ZedGraph              //保存位置
219using ZedGraph             // ZedGraphWeb1.RenderedImagePath = "~/Image/";
220using ZedGraph          }

221using ZedGraph      }
222using ZedGraph
223using ZedGraph

 

using ZedGraph
using ZedGraph

转载于:https://www.cnblogs.com/wt0731/archive/2007/08/28/873216.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2021-09-11
  • 2022-01-13
  • 2022-01-02
相关资源
相似解决方案