您的位置:首页 > 编程语言 > C#

C# 动态显示曲线

2016-05-11 11:40 435 查看
form窗体代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Data.OleDb;
using System.IO;

namespace ShowCurve
{
public partial class Form1 : Form
{
Thread thread;
ShowCurve sc;

public Form1()
{
InitializeComponent();
#region axST_Curve初始化
axST_Curve1.EnableHelpTip(false);//隐藏帮助信息
axST_Curve1.EnablePreview(false);//隐藏全局预览窗口
axST_Curve1.SetShowMode(128);//设置坐标显示模式
axST_Curve1.SetHPrecision(0);//设置横坐标显示精度
axST_Curve1.SetHInterval(2);//设置横坐标刻度值
axST_Curve1.SetVPrecision(0);//设置纵坐标显示精度
axST_Curve1.EnableZoom(true);
#endregion
sc = new ShowCurve();
thread = new Thread(new ThreadStart(Run));
thread.Start();
}
int pointCount=0;
private void Run()
{
Pen p1 = new Pen(System.Drawing.Color.FromArgb(0, 255, 255));
axST_Curve1.AddLegendHelper(11, "小车运行轨迹曲线", p1.Color.ToArgb(), 0, 1, false);
sc.GetCurrentCurve();
List<float> list1 = sc.getData1();
List<float> list2 = sc.getData2();
while (pointCount+1<list1.Count)
{
for (int i = pointCount; i <pointCount+ 1; i++)
{
axST_Curve1.AddMainData2(11, list1[i], list2[i], 0, 0, true);
if ( i % 100 == 0 && i > 0 )
{
axST_Curve1.DelRange(11, 1000,0, 0,true, true);
}
axST_Curve1.SetValueStep(400f);
axST_Curve1.SetVInterval(5);
axST_Curve1.SetHInterval(20);
axST_Curve1.SetTimeSpan(400);//设置坐标间隔
axST_Curve1.SetBeginValue(-800);
axST_Curve1.SetBeginTime2(-800);
axST_Curve1.SetZoom(20);
}
axST_Curve1.Refresh();
pointCount = pointCount + 1;
Thread.Sleep(1000);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//在窗体即将关闭之前中止线程
thread.Abort();
}
private void Form1_Load(object sender, EventArgs e)
{

}

}

}


类ShowCurve.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using System.Drawing;
using System.Data.OleDb;
using AxST_CurveLib;

namespace ShowCurve
{
class ShowCurve
{
List<float> list1 = new List<float>();
List<float> list2 = new List<float>();
public void GetCurrentCurve( )
{
//创建数据库字符串D:\小例子\ConsoleApplication1\FormRealTime\bin\Debug\data
string constr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Directory.GetCurrentDirectory() + "\\data\\db.accdb";
//创建数据库连接
using (OleDbConnection con = new OleDbConnection(constr))
{
//数据库语句
string selectStr = "select x,y from XYData where epc='car1'";
using (OleDbCommand cmd = new OleDbCommand(selectStr, con))
{
//打开数据库
con.Open();
//读取数据
using (OleDbDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
list1.Add(reader.GetFloat(0));
list2.Add(reader.GetFloat(1));
}
}
}
}
}
}
public List<float> getData1()
{
return list1;
}
public List<float> getData2()
{
return list2;
}
}

}


利用的是第三方画图控件ST_Curve,下载地址是:http://www.st-curve.cn/。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: