簡介:
即時曲線組件是以曲線來顯示採集的資料,可用於工業即時檢測等相關領域。
此組件支援多路曲線同時顯示;
也支援後期資料的顯示處理;
還提供了多圖對比的功能。
最重要的是支援縮放顯示功能,可無級放大需要的位置進行查看。
開發環境: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();
- }
- }
- }
:
在繪圖區域拉出一個選區後可以放大顯示該選區,雙擊滑鼠回退到上一個選區,支援無限放大,為放大後效果:
擷取方式:http://item.taobao.com/item.htm?id=4546003182