ZedGraph 是用于创建任意数据的二维线型、棒型、饼型图表的一个类库,也可以作为 Windows 窗体用户控件和 ASP 网页访问控件。这个类库具有高度的灵活性,几乎所有式样的图表都能够被创建。关于zedgraph控件的使用具体。参考官网介绍:http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET

在项目中遇到的问题总结如下:

一、曲线图基本参数设置:

//标题和x轴、y轴标签

this.zedGraphControl1.GraphPane.Title.Text = "实时曲线图";
             this.zedGraphControl1.GraphPane.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.Title.FontSpec.Size = 30f;

this.zedGraphControl1.GraphPane.XAxis.Title.Text = "时间";
             this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.Size = 20f;

this.zedGraphControl1.GraphPane.YAxis.Title.Text = "温度(℃)";
             this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.Size = 20f;
             //刻度值字体大小、颜色
             this.zedGraphControl1.GraphPane.XAxis.Scale.FontSpec.Size = 20f;
             this.zedGraphControl1.GraphPane.XAxis.Scale.FontSpec.FontColor = Color.Black;

this.zedGraphControl1.GraphPane.YAxis.Scale.FontSpec.Size = 20f;
             this.zedGraphControl1.GraphPane.YAxis.Scale.Min = 0;
             this.zedGraphControl1.GraphPane.YAxis.Scale.Max = 100;
             this.zedGraphControl1.GraphPane.YAxis.Scale.MinorStep = 1;//小步长
             //x轴数据类型
             this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;
             this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.Date;
             this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.Text;//显示文本
             this.zedGraphControl1.GraphPane.XAxis.Scale.Format = "HH:mm:ss";//时间格式
             //yy-mm-dd HH:mm:ss  其中HH是24小时制  hh是12小时制
             //显示网格线
             this.zedGraphControl1.GraphPane.YAxis.MajorGrid.IsVisible = true;
             this.zedGraphControl1.GraphPane.XAxis.MajorGrid.IsVisible = true;
             //legend图例
             this.zedGraphControl1.GraphPane.Legend.FontSpec.Size = 10f;
             this.zedGraphControl1.GraphPane.Legend.Position = LegendPos.Right;
             //面板填充颜色
             this.zedGraphControl1.GraphPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
            //在面板上添加文本
            TextObj text2 = new TextObj(
                "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",
                0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
            text2.FontSpec.StringAlignment = StringAlignment.Near;
            this.zedGraphControl1.GraphPane.GraphObjList.Add(text2);
            //添加箭头图案
            ArrowObj myArrow = new ArrowObj(Color.Red, 12F, 230F, 70F, 280F, 55F);
            this.zedGraphControl1.GraphPane.GraphObjList.Add(myArrow);
        // get a reference to the GraphPane
        GraphPane myPane =zedGraphControl1.GraphPane;
        // Set the Titles
        myPane.Title.Text = "My Test Graph\n(For CodeProject Sample)";
        myPane.XAxis.Title.Text = "My X Axis";
        myPane.YAxis.Title.Text = "My Y Axis";

//设置图表大小
            this.zedGraphControl1.Location = new Point(10, 10);
            this.zedGraphControl1.Size = new Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20);
二、曲线的实时显示:            
            //显示曲线 
            list.Add(x,y);//添加数据点
            LineItem mycurve = zedGraphControl1.GraphPane.AddCurve
                 ("温度传感器1", list, Color.Red, SymbolType.Square);
            //LineItem mycurve = zedGraphControl1.GraphPane.AddCurve
            //               ("温度传感器1", null, Ty, Color.Red, SymbolType.Square);
            //this.zedGraphControl1.GraphPane.XAxis.Scale.TextLabels = Tx;
            mycurve.Symbol.Size = 5.0f;//节点图案大小
            mycurve.Line.Width = 2.0F;//线宽
            //在面板上添加文本
            TextObj text = new TextObj(y.ToString("") + "℃",
                x, y*1.02, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            text.FontSpec.Size = 15f;
            text.FontSpec.FontColor = Color.Black;
            text.FontSpec.Border.IsVisible = false;
            text.FontSpec.Fill.IsVisible = true;
            text.ZOrder = ZOrder.A_InFront;
            text.FontSpec.Fill = new Fill(Color.FromArgb(240, Color.Snow));
            // Rotate the text to 90 degrees
            //text.FontSpec.Angle = 60;  //字体倾斜度
            this.zedGraphControl1.GraphPane.GraphObjList.Add(text);
            //更新坐标轴
            this.zedGraphControl1.AxisChange();
            //更新图像
            this.zedGraphControl1.Refresh();
            //同时清除该点的值!!注意索引   节点值刷新慢一拍
            if (list.Count >= 9) this.zedGraphControl1.GraphPane.GraphObjList.RemoveAt(1);//删除改点处的文本
            if (list.Count >= 10) list.RemoveAt(0);//大于10个点就删除第一个点
根据上面的设置就可以很容易定制自己的曲线图了。

三、程序参考:

<span style="font-size:14px;">        //标题、标签
             this.zedGraphControl1.GraphPane.Title.Text = "实时曲线图";
             this.zedGraphControl1.GraphPane.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.Title.FontSpec.Size = 30f;
             this.zedGraphControl1.GraphPane.XAxis.Title.Text = "时间";
             this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.Size = 20f;
             this.zedGraphControl1.GraphPane.YAxis.Title.Text = "温度(℃)";
             this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
             this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.Size = 20f;
             //this.zedGraphControl1.GraphPane.Chart.Border.Color  = Color .White  ;
             this.zedGraphControl1.GraphPane.Chart.IsRectAuto =true ;
             //刻度值字体大小
             this.zedGraphControl1.GraphPane.XAxis.Scale.FontSpec.Size = 20f;
             this.zedGraphControl1.GraphPane.YAxis.Scale.FontSpec.Size = 20f;
             this.zedGraphControl1.GraphPane.YAxis.Scale.Min = 0;
             this.zedGraphControl1.GraphPane.YAxis.Scale.Max = 50;
             //x轴类型
             this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.Date;
             this.zedGraphControl1.GraphPane.XAxis.Scale.Format = "HH:mm:ss";
             //显示网格线
             this.zedGraphControl1.GraphPane.YAxis.MajorGrid.IsVisible = true;
             this.zedGraphControl1.GraphPane.XAxis.MajorGrid.IsVisible = true;
             //legend
             this.zedGraphControl1.GraphPane.Legend.FontSpec.Size = 10f;
             this.zedGraphControl1.GraphPane.Legend.Position = LegendPos.InsideTopRight;
             //面板填充颜色
             this.zedGraphControl1.GraphPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
             //设置窗口大小
             SetSize();
             //更新画面
             this.zedGraphControl1.AxisChange();
             this.zedGraphControl1.Refresh();
</span>

定时显示程序:
<span style="font-size:14px;">         private void timer2_Tick(object sender, EventArgs e)
         {
                 this.zedGraphControl1.GraphPane.CurveList.Clear();
                 //温度曲线1
                 try
                 {
                     y = Convert.ToDouble(Convert.ToInt16(strTempureArry[4]) / 100.00); ;
                 }
                 catch
                 {
                     return;
                 }
                 //存储数据     
                 StoreDataDelegate myStoreDataDelegate = new StoreDataDelegate(StoreData);//实例化委托
                 myStoreDataDelegate(DateTimeNow, y);//调用委托
 
                 list.Add(x, y);               
                 LineItem mycurve = zedGraphControl1.GraphPane.AddCurve
                                   ("温度传感器1", list, Color.Red, SymbolType.Circle);                          
                 mycurve.Line.Width = 2.0F;//线宽
                 TextObj textT1 = new TextObj(y.ToString("") + "℃",
                        x, y*1.02, CoordType.AxisXYScale, AlignH.Center , AlignV.Bottom);
                 textT1.FontSpec.Size = 10f;
                 textT1.FontSpec.FontColor = Color.Red;
                 textT1.FontSpec.Fill.IsVisible = false;
                 textT1.FontSpec.Border.IsVisible = false;
                 //textT1.ZOrder = ZOrder.A_InFront;
                 //textT1.FontSpec.Fill = new Fill(Color.FromArgb(240, Color.Snow));
                 this.zedGraphControl1.GraphPane.GraphObjList.Add(textT1);
 
                 this.zedGraphControl1.AxisChange();
                 this.zedGraphControl1.Refresh();
                 //this.zedGraphControl1.Invalidate();
                 if (list.Count >= 10)
                 {
                     list.RemoveAt(0);
                     //同时清除该点的值
                     this.zedGraphControl1.GraphPane.GraphObjList.RemoveAt(0);
                 }
 
         }
</span>

控件大小设置:

private void SetSize()
         {
             zedGraphControl1.Location = new Point(10, 10);
             zedGraphControl1.Size = new Size(ClientRectangle.Width - 100, ClientRectangle.Height - 200);
         }

zedgraph控件使用相关推荐

  1. zedgraph控件的一些比较有用的属性(转)

    (1)zedgraph控件属性具体解释: AxisChange()() ->> This performs an axis change command on the graphPane. ...

  2. 在Project中引用zedgraph控件

    在Project中引用控件 一般情况下,此控件应该是使用在表现层(UI层),所以你可以直接在你的UI层直接引用,当然,为了你方便使用,你可以先把他加到控件箱里头(ToolBox) 方法: 对着控件箱右 ...

  3. Winform中怎样跨窗体获取另一窗体的控件对象

    场景 Winform中实现跨窗体获取ZedGraph的ZedGraphControl控件对象: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/de ...

  4. DevExpress的进度条控件ProgressBarControl的使用-以ZedGraph添加曲线进度为例

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  5. Winform中实现跨窗体获取ZedGraph的ZedGraphControl控件对象

    场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  6. 几个不错的开源的.net界面控件

    转自原文 几个不错的开源的.net界面控件 (转) 几个不错的开源的.net界面控件 - zt 介绍几个自己觉得不错的几个开源的.net界面控件,不知道是否有人介绍过. DockPanel Suite ...

  7. C#自定义工业控件开发

    由于工作需要,调研过一段时间的工业控制方面的"组态软件"(SCADA)的开发,组态软件常用于自动化工业控制领域,其中包括实时数据采集.数据储存.设备控制和数据展现等功能.其中工控组 ...

  8. 使用Aspose.Cell控件实现Excel高难度报表的生成(三)

    在之前几篇文章中,介绍了关于Apsose.cell这个强大的Excel操作控件的使用,相关文章如下: 使用Aspose.Cell控件实现Excel高难度报表的生成(一) 使用Aspose.Cell控件 ...

  9. matlab第三方控件,第三方控件介绍

    ILNumercis ILNumerics是一种NET框架的高性能数学库,它简化了各种数学算法的使用,使用起来和MATLAB类似.另外,ILNumerics具有超强绘图功能,如果希望在程序中加入类似M ...

  10. 几个不错的开源的.net界面控件[转贴]

    (http://zzdfc.cnblogs.com/articles/420822.html) 几个不错的开源的.net界面控件 - zt 介绍几个自己觉得不错的几个开源的.net界面控件,不知道是否 ...

最新文章

  1. python的with语句
  2. phd or domain
  3. 初识ABP vNext(8):ABP特征管理
  4. html5 多文件选择
  5. 输入矩阵java_java如何输入一个自定义矩阵
  6. 修炼Python基础篇-set学习
  7. SQL Server读懂语句运行的统计信息 SET STATISTICS TIME IO PROFILE ON
  8. python基础--综合练习(之王者荣耀小游戏)
  9. python音频识别_音频识别和比较
  10. [SourceTree - Git] 如何解决冲突 (以我的版本解决冲突以他人版本解决冲突)
  11. 在Hbuilder X中配置夜神模拟器
  12. 计算机第三课细心小编辑教案,教案-第6课小小编辑师
  13. 服务器双向同步文件,lsyncd配置两台服务器文件双向实时同步
  14. java 加密与解密算法,简单地加密和解密算法(java实现)
  15. csv日文乱码问题的解决
  16. java怎么绘画坦克_坦克游戏教程一:使用java绘图功能绘制简单坦克
  17. JAVA、PHP身份证、统一社会信用代码算法解析验证
  18. TensorFlow2.0选择GPU或CPU训练
  19. ldd 执行结果:不是动态可执行文件
  20. 通过git提交网站到码云(gitee)并部署发布静态网站

热门文章

  1. AutoCAD二次开发基础(二):曲线操作
  2. 华为服务器双系统教程,双系统安装教程
  3. CIH病毒的分析与清除
  4. 微信小程序图片下边加文字组合
  5. ffplay 分析概述
  6. pg数据库创建触发器
  7. xtrabackup备份mysql实战_Xtrabackup备份mysql实战(做从库全过程)
  8. Java菜鸟入坑——字符串中输出数字
  9. PHPWAMP出现无响应的解决方案,PHPWAMP集成环境在某些系统无响应什么办?
  10. CRNN——文本识别算法