公司有个需求,需要做嵌入式开发,跟硬件通信,把数据实时展示到winform中,网上查了资料,先写下个demo备用,到时候接入socket通信就完成了,具体效果如图

实现的原理是把最开始的数据去掉,加入新的数据,接着不停的绑定曲线数据,就能达到曲线实时展示的效果了

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
lb_shebei.Text = "等待设备连接";
c1.ChartAreas[].Axes[].MajorGrid.Enabled = false;//X轴上网格
c1.ChartAreas[].Axes[].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //y轴网格类型 短横线
c1.ChartAreas[].Axes[].MajorGrid.LineColor = Color.Gray;//Y轴网格线颜色
c1.ChartAreas[].Axes[].MajorTickMark.Enabled = false;// x轴上突出的小点
c1.ChartAreas[].AxisX.Enabled = AxisEnabled.False;//设置x轴不显示
c1.ChartAreas[].Axes[].MajorTickMark.Enabled = false;//y轴上突出的小点
c1.ChartAreas[].Axes[].IsInterlaced = false; //显示交错带
//c1.ChartAreas[0].Axes[0].LabelStyle.Format = "#年"; //设置X轴显示样式
c1.Series[].IsValueShownAsLabel = true;//曲线点是否显示值
c1.Legends[].Docking = Docking.Bottom;//调整图例位置
c1.Legends[].Alignment = StringAlignment.Center;//调整图例位置
c1.Series[].ChartType = SeriesChartType.Spline;//图表类型
c1.Series[].MarkerStyle = MarkerStyle.None; //标记点类型
c1.Series[].XValueType = ChartValueType.Time;//x轴坐标类型
c1.Series[].Name = "应力监测";
//c1.Series[0].IsValueShownAsLabel = true;//显示数值 Thread t1 = new Thread(MyLine);
t1.IsBackground = true;
t1.Start();
}
List<DateTime> xlist = new List<DateTime>();
List<int> ylist = new List<int>();
void BindData()
{
Random rd = new Random();
DateTime dt = DateTime.Now;
ylist.Add(rd.Next(-, ));
xlist.Add(dt);
if (xlist.Count > )
{
ylist.Remove(ylist[]);
xlist.Remove(xlist[]);
}
}
public void MyLine()
{
while (true)
{
BindData();
BindZp(xlist, ylist);
Thread.Sleep();
}
}
delegate void SetXCallback(List<DateTime> x, List<int> y);
void BindZp(List<DateTime> x, List<int> y)
{
if (c1.InvokeRequired)
{
SetXCallback d = new SetXCallback(BindZp);
this.Invoke(d, new object[] { x, y });
}
else
{
c1.Series[].Points.DataBindXY(x, y);//绑定数据
}
}
private void btn_out_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("正在数据传输,确定要退出吗?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
{
Application.Exit();
this.Dispose();
this.Close();
}
}
}

c#winform图表控件使用示例的更多相关文章

  1. asp.net微软图表控件使用示例

    <configuration> <system.webServer> <handlers> <remove name="ChartImageHand ...

  2. 二十六、【开源框架】EFW框架Winform前端开发之Grid++Report报表、条形码、Excel导出、图表控件

    回<[开源]EFW框架系列文章索引>        EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan ...

  3. .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll

    这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...

  4. 微软Charting图表控件 System.Web.UI.DataVisuliztion.Charting

    一.概述 基于.NET Framework 3.5 SP1的图表控件--Chart,可在WinForm和WebForm下使用!需要引入System.Web.DataVisualization.dll ...

  5. 问题:MSChart.exe;结果:微软图表控件MsChart使用方法及各种插件下载地址

    微软图表控件MsChart使用方法及各种插件下载地址 (2012-08-10 17:32:33) 转载▼ 标签: 图表 控件 下载地址 kernel32 微软 it 分类: C# 昨天在网上看到了微软 ...

  6. ASP.NET Core MVC TagHelper实践HighchartsNET快速图表控件-开源

    ASP.NET Core MVC TagHelper最佳实践HighchartsNET快速图表控件支持ASP.NET Core. 曾经在WebForms上写过 HighchartsNET快速图表控件- ...

  7. 图表控件的学习===》hightChart 和 Chartjs的使用

    hightChart : 比较旧的图表控件   商业需要授权 Chartjs 免费开源 刚开始使用了下 hightchart 然后参考示例 建了对应的参数配置的类, 也顺利的集合到后台动态传输.  后 ...

  8. .net CHARTING图表控件下载地址

    .net CHARTING是一款功能强大的图表控件,利用.NET framework和GDI+为工作于ASP.NET和Winform的C#和VB.NET开发人员提供可托管的图表解决方案,提供了多种2D ...

  9. echart图表控件配置入门(一)

    现在主流的web图表控件主要有hightchart.fusionchart.echart: echart作为百度前端部门近期推出的一个基于html5的免费图表控件,以其丰富图表类型和良好的兼容性速度得 ...

随机推荐

  1. spark学习14(spark local模式运行spark程序的报错)

    报错1 java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. 解 ...

  2. jQuery对象和dom对象的转换

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Linux平台下Oracle定时备份数据

    临时收到一个任务,就是在生产环境上定时备份oracle的数据.空闲时间搞了一下,真是一波三折,过程有点小郁闷,结果哈哈.现在进行总结一下 (1)新建一个shell脚本test.sh #!/bin/ba ...

  4. Pandas与SQL比较

    由于许多潜在的Pandas用户对SQL有一定的了解,因此本文章旨在提供一些如何使用Pandas执行各种SQL操作的示例. import pandas as pd url = 'tips.csv' ti ...

  5. Java中如何指定跳出多重嵌套循环

    今天做项目优化涉及到一个跳出指定多重嵌套循环的问题,觉得还是记录一下那么在Java中如何跳出当前的多重嵌套循环? 方法一:可以在需要的循环语句前定义一个标号,然后在里层循环体的代码中使用带有标号的br ...

  6. mysql 出现Host 'localhost' is not allowed to connect to this MySQL server 错误

    MySql数据库:Host 'localhost' is not allowed to connect to this MySQL server 修改mysql的root密码后,出现Host 'loc ...

  7. 创建CMD启动环境

    我们可以用一个cmd文件,通过doskey命令模拟linux下的alias,指定一些我们习惯的命令名,比如: env.cmd @echo off doskey alias=doskey /macros ...

  8. 019对象——对象 method_exists property_exists instanceof

    <?php /** * 19 对象 method_exists property_exists instanceof */ //method_exists() 判断方法是否存在,第一个参数对象或 ...

  9. 2017.11.23 display fun --STM8

    unsigned char disp_mode;unsigned char disp_last_mode;unsigned char disp_sub_mode;unsigned char disp_ ...

  10. php中生成树形菜单

    废话不多说!上代码 class tree { /** * 生成树型结构所需要的2维数组 * @var array */ var $arr = array(); /** * 生成树型结构所需修饰符号,可 ...