即時曲線組件 2.0

來源:互聯網
上載者:User

簡介:

    即時曲線組件是以曲線來顯示採集的資料,可用於工業即時檢測等相關領域。

        此組件支援多路曲線同時顯示;

        也支援後期資料的顯示處理;

        還提供了多圖對比的功能。

        最重要的是支援縮放顯示功能,可無級放大需要的位置進行查看。

 

開發環境: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) 設定圖形的最底層座標範圍,水平方向為時間,單位:分鐘;縱向為數值型,支援負值。

樣本:

  1. using
     System;
  2. using
     System.Collections.Generic;
  3. using
     System.ComponentModel;
  4. using
     System.Data;
  5. using
     System.Drawing;
  6. using
     System.Text;
  7. using
     System.Windows.Forms;
  8. using
     System.IO;
  9. namespace
     System.Shangfei.Drawing.Plot
  10. {
  11.     
    /// <summary>
  12.     
    /// 
  13.     
    /// </summary>
  14.     
    public
     partial 
    class
     Form1 : Form
  15.     {
  16.         
    /// <summary>
  17.         
    /// 
  18.         
    /// </summary>
  19.         
    public
     Form1()
  20.         {
  21.             InitializeComponent();
  22.             rnd = 
    new
     Random();
  23.             propertyGrid1.SelectedObject = plotEx1;
  24.         }
  25.         
    private
     
    void
     toolStripButton2_Click(
    object
     sender, EventArgs e)
  26.         {
  27.             
    this
    .plotEx1.DataSeries.Clear();
  28.             
    this
    .plotEx1.updateRootRect(0, 0, 20, 1000);
  29.             PlotInfomation pi = 
    new
     PlotInfomation();
  30.             pi.Name = 
    "曲線1"
    ;
  31.             pi.LineColor = Color.Red;
  32.             pi.PointCountPerMinute = 30;
  33.             pi.DataPoints = 
    new
     List<
    float
    >();
  34.             
    this
    .plotEx1.DataSeries.Add(pi);
  35.             PlotInfomation pi2 = 
    new
     PlotInfomation();
  36.             pi2.Name = 
    "曲線2"
    ;
  37.             pi2.LineDashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
  38.             pi2.LineColor = Color.Green;
  39.             pi2.PointCountPerMinute = 50;
  40.             pi2.DataPoints = 
    new
     List<
    float
    >();
  41.             
    this
    .plotEx1.DataSeries.Add(pi2);
  42.             timer1.Enabled = 
    true
    ;
  43.         }
  44.         
    private
     Random rnd = 
    null
    ;
  45.         
    private
     
    float
     OldValue = 100;
  46.         
    private
     
    void
     timer1_Tick(
    object
     sender, EventArgs e)
  47.         {
  48.             
    float
     f = OldValue + (
    float
    )rnd.NextDouble() * 4 - 2;
  49.             
    if
     (f < 0)
  50.                 f = 0;
  51.             
    if
     (f >1000)
  52.                 f = 1000;
  53.             
    this
    .plotEx1.DataSeries[0].DataPoints.Add(f);
  54.             
    this
    .plotEx1.DataSeries[1].DataPoints.Add(f + rnd.Next(10) - 5);
  55.             OldValue = f;
  56.             
    this
    .plotEx1.Invalidate();
  57.         }
  58.         
    private
     
    void
     toolStripButton1_Click(
    object
     sender, EventArgs e)
  59.         {
  60.             timer1.Enabled = 
    false
    ;
  61.         }
  62.         
    private
     
    void
     toolStripButton4_Click(
    object
     sender, EventArgs e)
  63.         {
  64.             SaveFileDialog sfd=
    new
     SaveFileDialog();
  65.             sfd.Filter=
    "文本資料|*.txt"
    ;
  66.             
    if
    (sfd.ShowDialog()==DialogResult.OK)
  67.             {
  68.                 StreamWriter sw = File.CreateText(sfd.FileName);
  69.                 
    this
    .plotEx1.SaveDataPoint(sw);
  70.                 sw.Close();
  71.                 
  72.             }
  73.             sfd.Dispose();
  74.         }
  75.         
    private
     
    void
     toolStripButton3_Click(
    object
     sender, EventArgs e)
  76.         {
  77.             OpenFileDialog ofd = 
    new
     OpenFileDialog();
  78.             ofd.Filter=
    "文本資料|*.txt"
    ;
  79.             
    if
     (ofd.ShowDialog() == DialogResult.OK)
  80.             {
  81.                 StreamReader sr = File.OpenText(ofd.FileName);
  82.                 
    this
    .plotEx1.LoadDataPoint(sr);
  83.                 sr.Close();
  84.                 
    //根據資料情況設定配量範圍
  85.                 
    this
    .plotEx1.updateRootRect(0, 0, 20, 1000);
  86.             }
  87.             ofd.Dispose();
  88.         }
  89.         
    private
     
    void
     toolStripButton5_Click(
    object
     sender, EventArgs e)
  90.         {
  91.             SaveFileDialog ofd = 
    new
     SaveFileDialog();
  92.             ofd.Filter=
    "圖形檔案|*.bmp"
    ;
  93.             
    if
     (ofd.ShowDialog() == DialogResult.OK)
  94.             {
  95.                 
    this
    .plotEx1.SaveImage(ofd.FileName);
  96.             }
  97.             ofd.Dispose();
  98.         }
  99.     }
  100. }

在繪圖區域拉出一個選區後可以放大顯示該選區,雙擊滑鼠回退到上一個選區,支援無限放大,為放大後效果:

 

擷取方式:http://item.taobao.com/item.htm?id=4546003182


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.