先看效果

官方例子修改过来的。对应代码如下

内部有相关的修改与中文注释

//============================================================================
//ZedGraph demo code
//The code contained in this file (only) is released into the public domain, so you
//can copy it into your project without any license encumbrance.  Note that
//the actual ZedGraph library code is licensed under the LGPL, which is not
//public domain.
//
//This file is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//=============================================================================using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;namespace ZGControlTest
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load( object sender, EventArgs e ){// Get a reference to the GraphPane instance in the ZedGraphControlGraphPane myPane = zg1.GraphPane;// Set the titles and axis labelsmyPane.Title.Text = " Demonstration of Dual Y Graph";myPane.XAxis.Title.Text = "Time, Days";myPane.YAxis.Title.Text = "Parameter A";myPane.Y2Axis.Title.Text = "Parameter B";myPane.Title.FontSpec.FontColor = Color.FromArgb(35, 70, 35); //标题文字颜色// Make up some data points based on the Sine functionPointPairList list = new PointPairList();PointPairList list2 = new PointPairList();for ( int i = 0; i < 36; i++ ){double x = (double)i * 5.0;double y = Math.Sin( (double)i * Math.PI / 15.0 ) * 16.0;double y2 = y * 13.5;list.Add( x, y );list2.Add( x, y2 );}// Generate a red curve with diamond symbols, and "Alpha" in the legendLineItem myCurve = myPane.AddCurve( "Alpha",list, Color.Red, SymbolType.Diamond );// Fill the symbols with whitemyCurve.Symbol.Fill = new Fill( Color.White );// Generate a blue curve with circle symbols, and "Beta" in the legendmyCurve = myPane.AddCurve( "Beta",list2, Color.Blue, SymbolType.Circle );//设置为点模式myCurve.Symbol.Type = SymbolType.Circle;myCurve.Symbol.Fill = new Fill(Color.Green); //填充颜色myCurve.Symbol.Size = 15;myCurve.Line.IsVisible = false;// true;// Fill the symbols with white//myCurve.Symbol.Fill = new Fill( Color.White );// Associate this curve with the Y2 axismyCurve.IsY2Axis = true;//添加第三y轴//myCurve.IsY2Axis = false;// Show the x axis gridmyPane.XAxis.MajorGrid.IsVisible = true;myPane.XAxis.Title.FontSpec.FontColor = Color.FromArgb(0, 128, 255); //x轴标题文字颜色myPane.XAxis.Scale.FontSpec.FontColor = Color.FromArgb(255, 128, 255); //x轴刻度颜色// Make the Y axis scale redmyPane.YAxis.Scale.FontSpec.FontColor = Color.Green; //y轴刻度颜色myPane.YAxis.Title.FontSpec.FontColor = Color.FromArgb(128,128,0); //y轴标题文字颜色// turn off the opposite tics so the Y tics don't show up on the Y2 axismyPane.YAxis.MajorTic.IsOpposite = false;myPane.YAxis.MinorTic.IsOpposite = false;// Don't display the Y zero linemyPane.YAxis.MajorGrid.IsZeroLine = false;// Align the Y axis labels so they are flush to the axismyPane.YAxis.Scale.Align = AlignP.Inside;// Manually set the axis rangemyPane.YAxis.Scale.Min = -30;myPane.YAxis.Scale.Max = 30;// Enable the Y2 axis displaymyPane.Y2Axis.IsVisible = true;// Make the Y2 axis scale bluemyPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;myPane.Y2Axis.Title.FontSpec.FontColor = Color.Pink;// turn off the opposite tics so the Y2 tics don't show up on the Y axismyPane.Y2Axis.MajorTic.IsOpposite = false;myPane.Y2Axis.MinorTic.IsOpposite = false;// Display the Y2 axis grid linesmyPane.Y2Axis.MajorGrid.IsVisible = true;// Align the Y2 axis labels so they are flush to the axismyPane.Y2Axis.Scale.Align = AlignP.Inside;// Fill the axis background with a gradientmyPane.Chart.Fill = new Fill( Color.White, Color.LightGray, 0.5f*45.0f ); //连个颜色的渐变,渐变角度设置// Add a text box with instructionsTextObj text = new TextObj("Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom );text.FontSpec.StringAlignment = StringAlignment.Near;myPane.GraphObjList.Add( text );// Enable scrollbars if neededzg1.IsShowHScrollBar = true;zg1.IsShowVScrollBar = true;zg1.IsAutoScrollRange = true;zg1.IsScrollY2 = true;// OPTIONAL: Show tooltips when the mouse hovers over a pointzg1.IsShowPointValues = true;zg1.PointValueEvent += new ZedGraphControl.PointValueHandler( MyPointValueHandler );// OPTIONAL: Add a custom context menu itemzg1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder );// OPTIONAL: Handle the Zoom Eventzg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler( MyZoomEvent );// Size the control to fit the windowSetSize();// Tell ZedGraph to calculate the axis ranges// Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets// up the proper scrolling parameterszg1.AxisChange();// Make sure the Graph gets redrawnzg1.Invalidate();}/// <summary>/// On resize action, resize the ZedGraphControl to fill most of the Form, with a small/// margin around the outside/// </summary>private void Form1_Resize( object sender, EventArgs e ){SetSize();}private void SetSize(){zg1.Location = new Point( 10, 10 );// Leave a small margin around the outside of the controlzg1.Size = new Size( this.ClientRectangle.Width - 20,this.ClientRectangle.Height - 20 );}/// <summary>/// Display customized tooltips when the mouse hovers over a point/// </summary>private string MyPointValueHandler( ZedGraphControl control, GraphPane pane,CurveItem curve, int iPt ){// Get the PointPair that is under the mousePointPair pt = curve[iPt];return curve.Label.Text + " is " + pt.Y.ToString( "f2" ) + " units at " + pt.X.ToString( "f1" ) + " days";}/// <summary>/// Customize the context menu by adding a new item to the end of the menu/// </summary>private void MyContextMenuBuilder( ZedGraphControl control, ContextMenuStrip menuStrip,Point mousePt, ZedGraphControl.ContextMenuObjectState objState ){ToolStripMenuItem item = new ToolStripMenuItem();item.Name = "add-beta";item.Tag = "add-beta";item.Text = "Add a new Beta Point";item.Click += new System.EventHandler( AddBetaPoint );menuStrip.Items.Add( item );}/// <summary>/// Handle the "Add New Beta Point" context menu item.  This finds the curve with/// the CurveItem.Label = "Beta", and adds a new point to it./// </summary>private void AddBetaPoint( object sender, EventArgs args ){// Get a reference to the "Beta" curve IPointListEditIPointListEdit ip = zg1.GraphPane.CurveList["Beta"].Points as IPointListEdit;if ( ip != null ){double x = ip.Count * 5.0;double y = Math.Sin( ip.Count * Math.PI / 15.0 ) * 16.0 * 13.5;ip.Add( x, y );zg1.AxisChange();zg1.Refresh();}}// Respond to a Zoom Eventprivate void MyZoomEvent( ZedGraphControl control, ZoomState oldState,ZoomState newState ){// Here we get notification everytime the user zooms}}
}

上面是官方例子做了相应的修改,增加了注释,

特此记录

by  anlog

2021年4月8日 22点27分

ZedGraph例子相关推荐

  1. ZedGraph webform 初学小例子 (代码有详细解释)

    ZedGraph是一个制作图表的类库,能够根据任意的数据生成各种2D线性图,柱状图,饼型图等.在Windows Forms和 ASP.Net Web Form中使用. 下面的例子是在Web Form中 ...

  2. ZedGraph在项目中的应用

    ZedGraph在项目中的应用<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" ...

  3. ZedGraph:一个同时支持WinForm和WebForm的开源图表控件(基于LGPL协议,.NET 2.0 C#源代码)...

    今天弟弟说想要实现Cross Tab(交叉表)的显示和图表显示,交叉表方面的东西以前找过一些,我博客里也有些介绍(C#实现Pivot(Cross Table)的一段代码和例子):于是上网搜索一番,找到 ...

  4. ZedGraph在Asp.net中的应用

    由于项目的需求图表显示数据,今天在网上找了一天,终于找到一个不错的控件----ZedGraph,它支持asp,asp.net,vc. 现在最新的版本是5.0,些版本支持   .NET 2.0.5.0版 ...

  5. ZedGraph给LineChart添加数值

    作为支持.net的强大的开源图表控件ZedGraph,最新版本是 New Update as of 28-Nov-2007 Version 5.1.4 + 4.6.4 官方主页:http://zedg ...

  6. ZedGraph使用经验

    开源的统计图控件中基本常用的是OpenFlashChar和ZedGraph,今天就先来讲讲ZedGraph的使用. ZedGraph资源 ZedGraph来源:http://sourceforge.n ...

  7. zedgraph画图

    用定时器超时来刷新数据,实现"连续"的图形输出. 1.       新建图像面板 GraphPane myPane = zedGraphControl1.GraphPane; 2. ...

  8. ZedGraph属性(转)

    ZedGraph属性(转) 是一个非常优秀的开源的作图控件 ZedGraph来源:http://sourceforge.net/project/showfiles.php?group_id=11467 ...

  9. 转载:ZedGraph使用帮助

    译文: 序言 ZedGraph是用于创建任意数据的二维线型.条型.饼型图表的一个类库,也可以作为Windows窗体用户控件和ASP网页控件(这里有个web-accessible 不知道该怎么翻译).这 ...

  10. C# 使用ZedGraph进行自定义绘图

    开源的统计图控件中基本常用的是OpenFlashChar和ZedGraph,今天就先来讲讲ZedGraph的使用. ZedGraph资源 ZedGraph来源:http://sourceforge.n ...

最新文章

  1. 操作-《oracle入门到精通》第六章开始
  2. Spring:SpringMVC一例
  3. .NET Framework 4.5 五个很棒的特性
  4. 每个程序员都可能犯过的10个错误
  5. 硬盘计算机类比推理,判断推理类比推理:储存:光盘:硬盘 A:晾晒:绳索:衣架 B.吃...
  6. RabbitMQ 下载安装配置_集群高可用篇_02
  7. 线性回归(三)---岭回归
  8. Mac只能读取不能修改硬盘文件怎么办?
  9. 计算机操作员管理规定,系统安全运行管理制度及保障措施
  10. 用Java实现家庭收支记账软件
  11. codeigniter mysql查询_codeigniter数据库操作函数汇总
  12. Java 随机数之从指定数据范围内随机选取n个不重复的数据
  13. 【学习笔记】统计学入门(6/7)——参数估计与可信区间
  14. gateway集成swagger
  15. pyqt 多窗口之间的相互调用方法
  16. 互联网日报 | 华为云年交易额超10亿元;恒大汽车拟申请科创板上市;李彦宏创立生命科学公司“百图生科”...
  17. ChatGPT基础知识系列之零样本学习( Zero-Short learning)
  18. 小米a1 android one,小米A1 Android One手机内存多少?小米A1手机内存大吗?[图]
  19. 2021-2027全球与中国汽车视觉摄像头市场现状及未来发展趋势
  20. Neo4j图数据库高性能入库方式

热门文章

  1. Matlab的复共轭转置
  2. iOS实现一个简单的视频播放器
  3. Postman 设置环境变量 个人记录
  4. NMAKE 详解(整理转载)
  5. 产品经理应具备的能力(初中高级),产品经理岗位细分
  6. 必学:入行电商产品经理必备知识,原来这么简单
  7. CH340G版USB转串口自动下载器原理图
  8. WinSock编程怎么把u_long型的IP地址转换为点分十进制
  9. 基于Dijkstra算法和KM算法的网约车订单分配问题
  10. frft雷达信号处理 论文