简介:
实时曲线组件是以曲线来显示采集的数据,可用于工业实时检测等相关领域。
此组件支持多路曲线同时显示;
也支持后期数据的显示处理;
还提供了多图对比的功能。
最重要的是支持缩放显示功能,可无级放大需要的位置进行查看。
开发环境:Visual Studio .Net 2005
关系图:
自定义属性:
| 属性名称 | 类型 | 说明 |
| AllowZoom | Bool | 是否允许缩放 |
| AxisNameX | string | X轴标题 |
| AxisNameY | string | Y轴标题 |
| AxisColor | Color | 坐标刻度线颜色 |
| DataSeries | Collection | 曲线的数据集合,PlotInfomation类的集合 |
| MaginLeft | int | 左边界的大小 |
| MaginTop | int | 上边界的大小 |
| MaginRight | int | 右边界的大小 |
| MaginButtom | int | 下边界的大小 |
| OffsetX | int | 显示多路曲线时,各曲线在X轴的相对偏移量 |
| OffsetY | int | 显示多路曲线时,各曲线在Y轴的相对偏移量 |
其中PlotInfomation的属性:
| 属性名称 | 类型 | 说明 |
| LineColor | Color | 曲线的颜色 |
| LineWidth | int | 曲线的粗细 |
| DataPoints | List<float> | 曲线的数据点 |
| LineDashStyle | DashStyle | 曲线的线型 |
| Name | string | 曲线的名称 |
| PointCountPerMinute | int | 每分钟包含的数据点个数 |
| Visible | bool | 曲线是否可见 |
方法:
| 方法名称 | 说明 |
| virtual void SaveDataPoint(BinaryWriter bw) | 以二进制保存曲线的数据 |
| virtual void SaveDataPoint(StreamWriter tw) | 以文本保存曲线的数据 |
| virtual void LoadDataPoint(BinaryReader bw) | 从二进制文件读取曲线的数据 |
| virtual void LoadDataPoint(StreamReader tw) | 从文本文件读取曲线的数据 |
| void SaveImage(string FileName) | 将当前图形保存到指定位图文件 |
| virtual void SaveImage(Graphics g) | 将当前图形保存到指定Graphics对象 |
| void updateRootRect(float x, float y, float width, float height) | 设置图形的最底层坐标范围,水平方向为时间,单位:分钟;纵向为数值型,支持负值。 |
示例:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace System.Shangfei.Drawing.Plot
- {
- /// <summary>
- ///
- /// </summary>
- public partial class Form1 : Form
- {
- /// <summary>
- ///
- /// </summary>
- public Form1()
- {
- InitializeComponent();
- rnd = new Random();
- propertyGrid1.SelectedObject = plotEx1;
- }
- private void toolStripButton2_Click( object sender, EventArgs e)
- {
- this .plotEx1.DataSeries.Clear();
- this .plotEx1.updateRootRect(0, 0, 20, 1000);
- PlotInfomation pi = new PlotInfomation();
- pi.Name = "曲线1" ;
- pi.LineColor = Color.Red;
- pi.PointCountPerMinute = 30;
- pi.DataPoints = new List< float >();
- this .plotEx1.DataSeries.Add(pi);
- PlotInfomation pi2 = new PlotInfomation();
- pi2.Name = "曲线2" ;
- pi2.LineDashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
- pi2.LineColor = Color.Green;
- pi2.PointCountPerMinute = 50;
- pi2.DataPoints = new List< float >();
- this .plotEx1.DataSeries.Add(pi2);
- timer1.Enabled = true ;
- }
- private Random rnd = null ;
- private float OldValue = 100;
- private void timer1_Tick( object sender, EventArgs e)
- {
- float f = OldValue + ( float )rnd.NextDouble() * 4 - 2;
- if (f < 0)
- f = 0;
- if (f >1000)
- f = 1000;
- this .plotEx1.DataSeries[0].DataPoints.Add(f);
- this .plotEx1.DataSeries[1].DataPoints.Add(f + rnd.Next(10) - 5);
- OldValue = f;
- this .plotEx1.Invalidate();
- }
- private void toolStripButton1_Click( object sender, EventArgs e)
- {
- timer1.Enabled = false ;
- }
- private void toolStripButton4_Click( object sender, EventArgs e)
- {
- SaveFileDialog sfd= new SaveFileDialog();
- sfd.Filter= "文本数据|*.txt" ;
- if (sfd.ShowDialog()==DialogResult.OK)
- {
- StreamWriter sw = File.CreateText(sfd.FileName);
- this .plotEx1.SaveDataPoint(sw);
- sw.Close();
- }
- sfd.Dispose();
- }
- private void toolStripButton3_Click( object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter= "文本数据|*.txt" ;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- StreamReader sr = File.OpenText(ofd.FileName);
- this .plotEx1.LoadDataPoint(sr);
- sr.Close();
- //根据数据情况设置量程范围
- this .plotEx1.updateRootRect(0, 0, 20, 1000);
- }
- ofd.Dispose();
- }
- private void toolStripButton5_Click( object sender, EventArgs e)
- {
- SaveFileDialog ofd = new SaveFileDialog();
- ofd.Filter= "图形文件|*.bmp" ;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- this .plotEx1.SaveImage(ofd.FileName);
- }
- ofd.Dispose();
- }
- }
- }
效果图:
在图形区域拉出一个选区后可以放大显示该选区,双击鼠标回退到上一个选区,支持无限放大,下图为放大后效果:
260

被折叠的 条评论
为什么被折叠?



