zedgraph怎么画曲线图_ZedGraph如何动态的加载曲线

本文介绍了如何使用ZedGraph控件在WinForm中动态加载和更新曲线数据,包括找到CurveItem、修改PointPairList、调用AxisChange()和Invalidate()等关键步骤。同时,文章还讨论了坐标轴的显示方式,如设置X轴为Log类型、控制10的幂显示以及调整字体角度等属性。
摘要由CSDN通过智能技术生成

ZedGraph的在线文档

官网的源代码 http://sourceforge.net/projects/zedgraph/?source=directory

zedgraph的demo在线范例

http://zedgraph.sourceforge.net/samples.html

这里介绍了如何实现动态加载数据,并且提供了demo

http://goorman.free.fr/ZedGraph/zedgraph.org/wiki/index3061.html?title=Display_Dynamic_or_Real-Time_Data

The ZedGraphControl can display dynamic or static data. For dynamic displays, each time you want to add data to a graph, you will need to do the following:

ZedGraph可以显示动态或者静态的数据,对于动态展示,每当你想要把数据加载到graph上的时候,你需要按照以下的步骤来做

1.Find the CurveItem of interest within the GraphPane.CurveList collection

第一步,先找到GraphPane.CurveList 中的相关曲线

2.Access the PointPairList (or other IPointListEdit type) for the CurveItem, and add the new data or modify the existing data as required

第二步,找到曲线中的PointPairList ,然后根据需要加载新数据或者修改已经存在的数据

3.Call ZedGr

要使用ZedGraph绘制曲线图,你需要做以下几个步骤: 1. 引用ZedGraph.dll程序集 在你的项目中添加对ZedGraph.dll程序集的引用。你可以在ZedGraph官网上下载最新版本的程序集。 2. 创建ZedGraph控件 在你的窗体或用户控件上创建一个ZedGraph控件。你可以在Visual Studio中从工具箱中拖动和放置ZedGraph控件,也可以在代码中创建它。 ```csharp using ZedGraph; // 创建一个名为"graphControl"的ZedGraph控件 ZedGraphControl graphControl = new ZedGraphControl(); this.Controls.Add(graphControl); ``` 3. 创建曲线对象 使用ZedGraph库中的LineItem类创建曲线对象,然后将数据点添加到曲线中。 ```csharp // 创建曲线对象 LineItem curve = graphControl.GraphPane.AddCurve("My Curve", new PointPairList(), Color.Blue, SymbolType.None); // 添加数据点 PointPairList pointList = new PointPairList(); pointList.Add(x1, y1); pointList.Add(x2, y2); // ... curve.Points = pointList; ``` 4. 配置图表属性 设置图表的标题、坐标轴标签、背景颜色等属性。 ```csharp // 设置图表属性 GraphPane myPane = graphControl.GraphPane; myPane.Title.Text = "My Graph"; myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; myPane.Fill = new Fill(Color.White, Color.LightGray, 45.0f); ``` 5. 刷新控件 最后,调用控件的Refresh方法来刷新曲线图。 ```csharp graphControl.AxisChange(); graphControl.Invalidate(); graphControl.Refresh(); ``` 完整的代码示例: ```csharp using ZedGraph; // 创建一个名为"graphControl"的ZedGraph控件 ZedGraphControl graphControl = new ZedGraphControl(); this.Controls.Add(graphControl); // 创建曲线对象 LineItem curve = graphControl.GraphPane.AddCurve("My Curve", new PointPairList(), Color.Blue, SymbolType.None); // 添加数据点 PointPairList pointList = new PointPairList(); pointList.Add(x1, y1); pointList.Add(x2, y2); // ... curve.Points = pointList; // 设置图表属性 GraphPane myPane = graphControl.GraphPane; myPane.Title.Text = "My Graph"; myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; myPane.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // 刷新控件 graphControl.AxisChange(); graphControl.Invalidate(); graphControl.Refresh(); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值