OxyPlot在WinForm中的应用
1、简介(从GitHub上复制)
Getting started
- Use the NuGet package manager to add a reference to OxyPlot (see details below if you want to use pre-release packages)
- Add a
PlotView
to your user interface - Create a
PlotModel
in your code - Bind the
PlotModel
to theModel
property of yourPlotView
Examples
You can find examples in the /Source/Examples
folder in the code repository.
NuGet packages
The latest pre-release packages are pushed by AppVeyor CI to myget.org To install these packages, set the myget.org package source https://www.myget.org/F/oxyplot
and remember the "-pre" flag.
The stable release packages will be pushed to nuget.org. Note that we have currently have a lot of old (v2015.*) and pre-release packages on this feed, this will be cleaned up as soon as we release v1.0.
Package | Targets | Dependencies |
---|---|---|
OxyPlot.Core | .NET Standard 1.0 | |
OxyPlot.Wpf | .NET 4.5.2 | |
OxyPlot.WindowsForms | .NET 4.5.2 | |
OxyPlot.Windows | Universal Windows 10.0 | |
OxyPlot.GtkSharp | .NET 4.5.2 | GTK# 2 |
OxyPlot.GtkSharp3 | .NET 4.5.2 | GTK# 3 |
OxyPlot.Xamarin.Android | MonoAndroid | |
OxyPlot.Xamarin.iOS | MonoTouch and iOS10 | |
OxyPlot.Xamarin.Mac | Mac20 | |
OxyPlot.Xamarin.Forms | MonoTouch, iOS10, MonoAndroid, WP8 | |
OxyPlot.Xwt | .NET 4.5.2 | |
OxyPlot.SharpDX.Wpf | .NET 4.5.2 | |
OxyPlot.Avalonia | .NET 4.5.2 | |
OxyPlot.OpenXML | .NET 4.5.2 | |
OxyPlot.Pdf | .NET 4.5.2 | PdfSharp |
OxyPlot.Contrib | .NET Standard 1.0 | |
OxyPlot.ExampleLibrary | .NET Standard 1.0 |
2、如何使用
在GitHub上面有一些简单的示例可以参考。但是在实际应用中并非如此简单,本示例主要介绍如何在winform中完成一个能够实时绘制动态曲线的目标
2.1、创建项目
创建项目名为OxyPlotWinform的winform工程,在项目的nuget搜索添加OxyPlot.WindowsForms库。
2.2、添加PlotView
在Form1中添加一个容器panel,设置为在父容器中停靠,在panel1中添加一个plotview,设置Dock为Fill。
2.3 添加代码
添加变量:
private DateTimeAxis _dateAxis;//X轴
private LinearAxis _valueAxis;//Y轴private PlotModel _myPlotModel;
private Random rand = new Random();//用来生成随机数
添加代码:
private void Form1_Load(object sender, EventArgs e){//定义model_myPlotModel = new PlotModel(){Title = "Temp & Humi",LegendTitle = "Legend",LegendOrientation = LegendOrientation.Horizontal,LegendPlacement = LegendPlacement.Inside,LegendPosition = LegendPosition.TopRight,LegendBackground = OxyColor.FromAColor(200,OxyColors.Beige),LegendBorder = OxyColors.Black};//X轴_dateAxis = new DateTimeAxis(){MajorGridlineStyle = LineStyle.Solid,MinorGridlineStyle = LineStyle.Dot,IntervalLength = 80,IsZoomEnabled = false,IsPanEnabled = false};_myPlotModel.Axes.Add(_dateAxis);//Y轴_valueAxis = new LinearAxis(){MajorGridlineStyle = LineStyle.Solid,MinorGridlineStyle = LineStyle.Dot,IntervalLength = 80,Angle = 60,IsZoomEnabled = false,IsPanEnabled = false,Maximum = 100,Minimum = -1};_myPlotModel.Axes.Add(_valueAxis);//添加标注线,温度上下限和湿度上下限var lineTempMaxAnnotation = new OxyPlot.Annotations.LineAnnotation(){Type = LineAnnotationType.Horizontal,Color = OxyColors.Red,LineStyle = LineStyle.Solid,Y = 10,Text = "Temp MAX:10"};_myPlotModel.Annotations.Add(lineTempMaxAnnotation);var lineTempMinAnnotation = new LineAnnotation(){Type = LineAnnotationType.Horizontal,Y = 30,Text = "Temp Min:30",Color = OxyColors.Red,LineStyle = LineStyle.Solid};_myPlotModel.Annotations.Add(lineTempMinAnnotation);var lineHumiMaxAnnotation = new OxyPlot.Annotations.LineAnnotation(){Type = LineAnnotationType.Horizontal,Color = OxyColors.Red,LineStyle = LineStyle.Solid,//lineMaxAnnotation.MaximumX = 0.8;Y = 75,Text = "Humi MAX:75"};_myPlotModel.Annotations.Add(lineHumiMaxAnnotation);var lineHumiMinAnnotation = new LineAnnotation(){Type = LineAnnotationType.Horizontal,Y = 35,Text = "Humi Min:35",Color = OxyColors.Red,LineStyle = LineStyle.Solid};_myPlotModel.Annotations.Add(lineHumiMinAnnotation);//添加两条曲线var series = new LineSeries(){Color = OxyColors.Green,StrokeThickness = 2,MarkerSize = 3,MarkerStroke = OxyColors.DarkGreen,MarkerType = MarkerType.Diamond,Title = "Temp",Smooth = true};_myPlotModel.Series.Add(series);series = new LineSeries(){Color = OxyColors.Blue,StrokeThickness = 2,MarkerSize = 3,MarkerStroke = OxyColors.BlueViolet,MarkerType = MarkerType.Star,Title = "Humi",Smooth = true};_myPlotModel.Series.Add(series);plotView1.Model = _myPlotModel;Task.Factory.StartNew(() =>{while (true){var date = DateTime.Now;_myPlotModel.Axes[0].Maximum = DateTimeAxis.ToDouble(date.AddSeconds(1));var lineSer = plotView1.Model.Series[0] as LineSeries;lineSer.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), rand.Next(100, 300)/10.0));if (lineSer.Points.Count > 100){lineSer.Points.RemoveAt(0);}lineSer = plotView1.Model.Series[1] as LineSeries;lineSer.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), rand.Next(350, 750)/10.0));if (lineSer.Points.Count > 100){lineSer.Points.RemoveAt(0);}_myPlotModel.InvalidatePlot(true);Thread.Sleep(1000);}});}
2.4、程序运行
项目地址:
1、https://gitee.com/sesametech-group/OxyPlotWinform
2、https://github.com/mzy666888/OxyPlotWinform
参考文献:
1、https://blog.csdn.net/mytinaonly/article/details/79926290
OxyPlot在WinForm中的应用相关推荐
- 在winform中从外部拖动节点到树形结构(treeview和listview相互拖动)(一)
最近一个项目要用到从listview向treeview拖动item,达到从外部拖动图标成为树形结构的一部分,通过查阅资料总结了一些实现方式,分享给大家.这是winform中的例子. 在进行拖放操作之前 ...
- C# winform中MouseDoubleClick与DoubleClick的区别
C# winform中MouseDoubleClick与DoubleClick的区别是 MouseDoubleClick:只能用鼠标双击 DoubleClick:可以按键盘的回车键
- C#在WinForm中实现清空指定类型控件的内容
实现在Winform中递归控件来清空指定类型控件的内容(因为在Winform中,各个控件是有层次关系的,不能简单地依靠遍历this.controls) private void ClearConten ...
- winform中构造函数与Form_Load
不都是用来初始化form中的组件么? public Form()所谓的构造函数. Form_Load所谓的窗体加载函数 完全两码事! WinForm 中的 Form_Load函数和他的构造函数 pub ...
- .NET WinForm中给DataGridView自定义ToolTip并设置ToolTip的样式
.NET WinForm中的DataGridView为程序开发提供了诸多的便利,我们不需要做许多额外的工作就可以获得一些基础功能,例如点击列标题排序.行选择功能.改变列宽和行宽,以及单元格内容的自动T ...
- 怎样正确处理WinForm中Listview的ItemCheck事件
我很少写具体的对象应用心得,这次尝试一下. WinForm中Listview的ItemCheck事件,例子如下: private void lvwTables_ItemCheck(object s ...
- 把控制台程序嵌入到 WinForm 中执行
我们经常有一些用控制台实现的简单应用,这种应用一般都是一步一步"向导"式执行,在每一步上收集用户的输入,最后得到程序执行的结果.但有些用户可能不喜欢用键盘操作的命令行界面,还是愿意 ...
- WinForm中的MVC模式--MVP模式
本文主要介绍MVC模式在WINFORM中的实现,其实砖家们都称它为MVP模式,小弟E文不太好,真的是记不住那个P怎么拼写的.. MVC模式主要解决的问题就是将表示层和业务层进行分离,在以往做WINFO ...
- 在WinForm中通过HTTP协议向服务器端上传文件(转)
相信用ASP.NET写一个上传文件的网页,大家都会写,但是有没有人想过通过在WinForm中通过HTTP协议上传文件呢? 有些人说要向服务器端上传文件,用FTP协议不是很简单吗?效率又高,为什么还要使 ...
最新文章
- s5pv210 linux内核移植,简单根文件系统制作 - S5PV210 Linux3.8.3内核移植_Linux编程_Linux公社-Linux系统门户网站...
- 网站建设技术方案_企业网站建设解决方案
- NYOJ 179 LK's problem
- Matplotlib 可视化之图表层次结构
- SAP JAM的dashboard
- Xilinx Vivado的使用详细介绍(2):综合、实现、管脚分配、时钟设置、烧写
- Dynamic Performance Tables not accessible,Automatic Statistics...
- h3csyslog_H3C Syslog简单配置
- NOI 2018 归程 (Kruskal重构树)
- Windows10 任务栏图标如何居中
- 固高控制卡Home捕获和Index捕获
- PDF复制文本快速去除换行,解决段落错乱
- Google Earth Engine(GEE)——导出视频和存储到云端!
- 兼职开发怎样才能变成技术合伙人?
- Android 11.0 12.0在系统app安装第三方app弹出 解析安装包出现问题 的解决方案
- matlab单边带调制器设计,通信系统综合设计与实践(基于MATLAB的单边带调制)研究.doc...
- mysql高级 tigger触发器 --[2]
- cgb2111-day01
- 上证指数预测之python建模与动态时间扭曲
- 人工智能ai发展前景_人工智能促进可持续发展的社会