C# 动态显示曲线
2016-05-11 11:40
435 查看
form窗体代码
类ShowCurve.cs代码
利用的是第三方画图控件ST_Curve,下载地址是:http://www.st-curve.cn/。
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/。
相关文章推荐
- c#中开发ActiveX的学习笔记【转】
- C#中Monitor和Lock以及区别
- C# winform Listbox添加和删除items
- 分享C#中几个可用的类
- C#程序输出信息到调试窗口的几种方式
- C#中Timer使用及解决重入问题
- C#运算符之与,或,异或及移位运算
- C#面向对象设计的七大原则
- C#开发中怎么提升excel导出速度
- C#实现简单的汽车租赁系统
- C# 委托 delegate
- c#中取整,向上取,向下取
- C# 判断文件夹存在与否并创建文件夹
- C#中的invoke和begininvoke
- C# 获取windows特殊路径
- 漫谈C#编程语言在游戏领域的应用
- C#动态编译、执行代码
- C#集合接口与集合类
- C#求自守数
- C#设计模式——观察者模式(Observer Pattern)