C#中如何利用LightningChart绘制曲线图表
1个回答
2018-03-29
展开全部
LightningChart的一个优点:在图中,通过鼠标滚轮,轻松实现放大缩小功能,便于观察曲线细节,下图为缩小放大效果:
绘制曲线的代码:
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 Arction.WinForms.Charting;using Arction.WinForms.Charting.SeriesXY;
namespace WindowsFormsApplication5{public partial class Form1 : Form{public Form1(){InitializeComponent();}//画线方法private void PaintLine(){DataBaseOpe ope = new DataBaseOpe();//禁用属性改变引起的重画,以便更快的渲染lightningChartUltimate1.BeginUpdate();//lightningChartUltimate1.Dock = DockStyle.Fill;//添加点线系列PointLineSeries pls = new PointLineSeries(lightningChartUltimate1.ViewXY,lightningChartUltimate1.ViewXY.XAxes[0],lightningChartUltimate1.ViewXY.YAxes[0]);//显示点pls.PointsVisible = false;SeriesPoint[] aPoints = new SeriesPoint[1000];for (int iPoint = 0; iPoint < ope.GetXmax() + 1; iPoint++){aPoints[iPoint].X = (double)iPoint;aPoints[iPoint].Y = ope.GetYvalue(iPoint);}//为点线系列分配数据pls.Points = aPoints;//将点线系列添加进列表lightningChartUltimate1.ViewXY.PointLineSeries.Add(pls);//允许Chart绘图lightningChartUltimate1.EndUpdate();}
private void buttonGO_Click(object sender, EventArgs e){DataBaseOpe ope = new DataBaseOpe();PIDdeal pid = new PIDdeal();//LightningChart初始化lightningChartUltimate1.ViewXY.PointLineSeries.Clear();//数据库初始化:清空数据库ope.ClearDataBase();//PID变量初始化pid.PIDinit();pid.SetValue = double.Parse(textBoxSetValue.Text);double p = double.Parse(textBoxKp.Text);double i = double.Parse(textBoxKi.Text);double d = double.Parse(textBoxKd.Text);for(int j = 0;j < 1000;j++){ope.AddData(j, pid.PIDcontrol(pid.SetValue, p, i, d));}PaintLine();}}}
实现上面图中效果,需要用到数据库操作和PID算法来实现,加上一个timer控件还可以实现实时曲线的绘制,
上图包含多种图表绘制的例子,可自定义实现数据可视化操作。
(简数科技 技术支持 免费中文)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询