C# 窗体应用程序 Chart控件显示实时曲线

IDE: VS2019
项目模板:C# windows 窗体应用(.NET Framework)

【参考】

  1. B站上教程C#Chart控件画折线图的使用,关于Chart控件的属性,介绍得非常详细。
  2. B站上教程C#上位机Chart控件实时曲线终极讲解,对鼠标滚轮事件等,多个事件的讲解较为详细。
  3. 工具箱中找不到Chart控件怎么办->VS/C#添加chart控件
    项目结构非常简单,一个窗体ArtDAQ.cs和一个主程序Program
    在这里插入图片描述# 【遇到的问题】
    Timer控件拖拽到设计器上,显示不出来,无法通过双击的方式给Timer控件添加事件
    手动写了一个InitializeTimer函数,在该函数中,给Timer控件的对象timer1绑定了一个事件timer1_Tick
timer1.Tick += new EventHandler(timer1_Tick);

InitializeTimer函数添加进ArtDAQ的构造函数中,然后在后面继续写timer1_Tick函数。
在这里插入图片描述
ArtDAQ.cs代码

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;namespace ArtDAQ
{public partial class ArtDAQ : Form{// 设置Tiemr事件的间隔事件private void InitializeTimer(){// 设置Timer事件的间隔时间(在此例中为2000毫秒)timer1.Interval = 100;// 启动Timer// timer1.Start();// 绑定Tick事件timer1.Tick += new EventHandler(timer1_Tick);}// 构造函数public ArtDAQ(){InitializeComponent();InitializeTimer();}// 触发按钮private void button1_Click(object sender, EventArgs e){if (timer1.Enabled == false){// timer1.Enabled = true;timer1.Start();MessageBox.Show(timer1.Enabled.ToString());}else{timer1.Enabled = false;}}// Timer的事件// 随机数Random rd = new Random();       int x = 0;int y = 0;private void timer1_Tick(object sender, EventArgs e){y = rd.Next(0, 100+1);chart1.Series[0].Points.AddXY(x, y);if(x>=101){timer1.Enabled = false;// timer1.Stop();}x++;}}
}

窗体设计文件ArtDAQ.Designer.cs


namespace ArtDAQ
{partial class ArtDAQ{/// <summary>/// Required designer variable./// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// Clean up any resources being used./// </summary>/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary>private void InitializeComponent(){this.components = new System.ComponentModel.Container();System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend();System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series();System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint3 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D);System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series();System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series();System.Windows.Forms.DataVisualization.Charting.Title title3 = new System.Windows.Forms.DataVisualization.Charting.Title();this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();this.timer1 = new System.Windows.Forms.Timer(this.components);this.button1 = new System.Windows.Forms.Button();((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();this.SuspendLayout();// // chart1// chartArea3.AxisX.Interval = 5D;chartArea3.AxisX.Maximum = 100D;chartArea3.AxisX.Minimum = 0D;chartArea3.AxisY.Interval = 5D;chartArea3.AxisY.Maximum = 100D;chartArea3.AxisY.Minimum = 0D;chartArea3.CursorX.IsUserEnabled = true;chartArea3.CursorX.IsUserSelectionEnabled = true;chartArea3.Name = "ChartArea1";chartArea3.Position.Auto = false;chartArea3.Position.Height = 90F;chartArea3.Position.Width = 90F;chartArea3.Position.X = 3F;chartArea3.Position.Y = 10F;this.chart1.ChartAreas.Add(chartArea3);legend3.Name = "Legend1";this.chart1.Legends.Add(legend3);this.chart1.Location = new System.Drawing.Point(19, 12);this.chart1.Name = "chart1";series7.ChartArea = "ChartArea1";series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;series7.Legend = "Legend1";series7.Name = "Series1";series7.Points.Add(dataPoint3);series8.ChartArea = "ChartArea1";series8.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;series8.Legend = "Legend1";series8.Name = "Series2";series9.ChartArea = "ChartArea1";series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;series9.Legend = "Legend1";series9.Name = "Series3";this.chart1.Series.Add(series7);this.chart1.Series.Add(series8);this.chart1.Series.Add(series9);this.chart1.Size = new System.Drawing.Size(692, 375);this.chart1.TabIndex = 0;this.chart1.Text = "chart1";title3.BorderWidth = 2;title3.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold);title3.ForeColor = System.Drawing.Color.CornflowerBlue;title3.Name = "Title1";title3.Text = "Chart1";this.chart1.Titles.Add(title3);// // timer1// // this.timer1.Tick += new System.EventHandler(this.timer1_Tick);// // button1// this.button1.Location = new System.Drawing.Point(734, 51);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(93, 47);this.button1.TabIndex = 1;this.button1.Text = "显示曲线";this.button1.UseVisualStyleBackColor = true;this.button1.Click += new System.EventHandler(this.button1_Click);// // ArtDAQ// this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(875, 473);this.Controls.Add(this.button1);this.Controls.Add(this.chart1);this.Name = "ArtDAQ";this.Text = "ArtDAQ";((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();this.ResumeLayout(false);}#endregionprivate System.Windows.Forms.DataVisualization.Charting.Chart chart1;private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Button button1;}
}

【项目地址】:

链接:https://pan.baidu.com/s/1HhBg620l0nMsSQ07j8MdOQ
提取码:6wnn
–来自百度网盘超级会员V5的分享

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/639954.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

今日arXiv最热NLP大模型论文:浙江大学:蒸一蒸,多Agent变成单一模型,效果更好

“团结就是力量”&#xff0c;面对复杂多变的现实环境&#xff0c;multi-agent应运而生。相较于单打独斗的single-agent&#xff0c;multi-agent集结了多个功能各异的LLM&#xff0c;共同攻克难关。然而&#xff0c;这种协同作战的方式也带来了沉重的推理负担&#xff0c;限制了…

【GDAL-Python】3-在Python中使用GDAL处理数字高程模型DEM

文章目录 1-介绍1.1 主要内容1.2 坡度、坡向、山体阴影 2-代码实现2.1 数据介绍2.2 代码实现2.3 效果显示 3.参考资料3.1 使用richdem库中的TerrainAttribute计算坡度、坡向、山体阴影 1-介绍 1.1 主要内容 &#xff08;1&#xff09;教程内容&#xff1a;使用GDAL处理数字高…

20240422,C++文件操作

停电一天之后&#xff0c;今天还有什么理由不学习呜呜……还是没怎么学习 一&#xff0c;文件操作 文件操作可以将数据持久化&#xff0c;对文件操作时须包含头文件<fstream> 两种文件类型&#xff1a;文本文件&#xff1a;文件以文本的ASCII码形式存储&#xff1b;二进…

Oracle21C 引入HR实例(linux)

1、下载资源 https://github.com/oracle-samples/db-sample-schemas点击code&#xff08;代码&#xff09;下载 2、上传Sql文件 解压之后将human_resources里的文件复制到demo\schema\目录&#xff08;具体目录前面的路径是你安装的路径&#xff09;下&#xff0c;如下图 3、…

李廉洋:4.23黄金休市之后大幅下跌,原油小幅度上涨。走势分析!

今年以来推动金价上涨的因素是亚洲的需求&#xff0c;很可能来自各国央行。最近又有零售买盘和一些金融买盘作为补充。目前的问题是&#xff0c;不断上升的债券收益率正在争夺资金。美国2年期国债的收益率接近5%&#xff0c;在美联储降息导致收益率开始下降之前&#xff0c;这仍…

软件公司:饥一顿饱一顿,咋办?试一试外部柔性产能。

有人开玩笑&#xff0c;软件公司最理想状态就是&#xff1a;项目来了&#xff0c;公司有足够的人力消化产能&#xff1b;项目没了&#xff0c;人员都走了&#xff0c;不会造成产能搁置。 以上是个理想状态&#xff0c;事实上单纯依靠一个公司是做不到的&#xff0c;所以一定建立…

网络常识!!!

网络常识!!! 一:网络的发展史二:关键的概念三:IP地址四:端口号二级目录二级目录二级目录二级目录三级目录 一:网络的发展史 从游戏方面发展历程进行理解: 从单机游戏-----游戏支持局域网对战-------游戏支持广域网对战-------移动端 (1)局域网对战:在同一个网吧里,不同的游戏…

【C++】---STL之vector详解

【C】---STL之vector详解 一、vector的介绍&#xff1a;二、vector的成员函数&#xff1a;1、vector类的构造函数2、vector的元素访问符3、vector的迭代器4、vector的模版5、vector的拷贝构造6、vector的容量&#xff08;1&#xff09;vector的增容机制&#xff08;2&#xff0…

计算机视觉 | 交通信号灯状态的检测和识别

Hi&#xff0c;大家好&#xff0c;我是半亩花海。本项目旨在使用计算机视觉技术检测交通信号灯的状态&#xff0c;主要针对红色和绿色信号灯的识别。通过分析输入图像中的像素颜色信息&#xff0c;利用OpenCV库实现对信号灯状态的检测和识别。 目录 一、项目背景 二、项目功能…

路由引入、路由策略、路由过滤实验

实验拓扑 实验思路 配置ip地址&#xff0c;配置RIP,OSPF;在R2上分别在RIP下引入OSPF&#xff0c;在OSPF下引入RIP;在R2上配置acl 2000,拒绝R4的业务网段&#xff0c;同时允许其他网段访问&#xff08;acl 2000 默认拒绝网段&#xff09;&#xff1b;通过配置路由过滤router-…

网络工程师----第九天

路由表解析 路由表&#xff1a;简单点说路由表就是路由器用于指导数据包如何转发的表项&#xff0c;记录了去往目的IP的下一跳去哪里。 路由&#xff1a;路由是网络中的基本概念&#xff0c;网络的基本功能就是使得处于网络中两个IP地址能够互相通信。 路由表作用&#xff1a…

YOLO算法改进Backbone系列之MogaNet:

卷积神经网络&#xff08;ConvNets&#xff09;一直是计算机视觉的首选方法。受灵长类视觉系统的启发&#xff0c;卷积层可以对具有区域密集连接和平移等方差约束的观测图像的邻域相关性进行编码。通过交错分层&#xff0c;ConvNets获得了被动增加的感受野&#xff0c;并善于识…