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);

        }

        #endregion

        private 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.mfbz.cn/a/557369.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

数据结构初阶-二叉树

&#x1f308;个人主页&#xff1a;羽晨同学 &#x1f4ab;个人格言:“成为自己未来的主人~” 二叉树 树概念和结构 树的概念 树是一种非线性的数据结构&#xff0c;它是由n&#xff08;n>0&#xff09;个有限节点组成的一个具有层次关系的集合&#xff0c;把它叫做树…

在H5开发App应用程序过程中的一些常见问题

哈喽&#xff0c;大家好呀&#xff0c;淼淼又来和大家见面啦&#xff0c;H5开发是一种可以跨平台、跨设备、且可以在各种设备上运行&#xff0c;无需安装额外的应用程序。最近有许多小伙伴跟我聊到在h5开发App应用程序的过程中遇到了一些问题&#xff0c;今天我们就这些问题来做…

赫克Hurco触摸屏维修工控机显示屏G190EG01

美国赫克Hurco工控机控制器维修C5SH11 Hurco工控机电脑维修 主要适用范围是&#xff1a;石油和石油化学工业、灶矿、油田、化学工业、化纤工业、油漆工业、肥料工业、各种制造工业。石油轮和车辆、飞机、仓库、电解车间、通讯机装配车间、要求工具不生锈、抗磁的场所等。 hurc…

SQL连接查询

连接查询&#xff1a; 同时涉及多个表的查询称为连接查询。 SQL中连接查询的主要类型 (1) 交叉连接&#xff08;广义笛卡尔积&#xff09; (2) 等值连接 (3) 自身连接 (4) 内连接 (5) 外连接 1.交叉连接 使用笛卡尔积运算的连接方式 笛卡尔积运算&#xff1a;设A&#xff…

Java 的注释

文章目录 java 的注释共有三种形式单行注释多行注释文档注释文档注释的文档需要命令进行生成GBK 不可映射问题 与大多数的编程语言一样&#xff0c;Java 中的注释也不会出现在可执行程序中。 因此我们可以在源程序中根据需要添加任意多的注释&#xff0c;而不必担心可执行代码受…

LeetCode:203.移除链表元素

&#x1f3dd;1.问题描述&#xff1a; &#x1f3dd;2.实现代码&#xff1a; typedef struct ListNode ListNode; struct ListNode* removeElements(struct ListNode* head, int val) {if(headNULL)return head;ListNode *NewHead,*NewTail;ListNode *pcurhead;NewHeadNewTail…

揭秘七星创客模式:如何轻松实现财富增长

亲爱的朋友们&#xff0c;我是微三云的周丽&#xff0c;一名专注于私域电商模式创新的探索者。 在当今商业社会&#xff0c;随着科技的飞速发展和互联网的普及&#xff0c;商业模式的创新和变革成为企业发展的关键。其中&#xff0c;七星创客模式以其独特的魅力和gao效的yun营…

这就是酷雷曼500位合作商成功的底气

你只管赚钱&#xff0c;其它交给总部&#xff01; 敢做出这样的承诺&#xff0c;酷雷曼凭的就是“保姆式”的帮扶政策。酷雷曼致力于建立一个可持续良效发展的合作商运营体系&#xff0c;无论是落地扶持还是培训服务&#xff0c;全方位为合作商保驾护航&#xff01; 陪跑式落…

注意力机制基本思想(一)

​&#x1f308; 个人主页&#xff1a;十二月的猫-CSDN博客&#x1f525; 系列专栏&#xff1a; &#x1f3c0;《深度学习基础知识》 相关专栏&#xff1a; ⚽《机器学习基础知识》 &#x1f3d0;《机器学习项目实战》 &#x1f94e;《深度学习项目实战…

超详细Web程序设计基础知识,新手设计师快收藏!

Web 程序设计是现代计算机科学的核心领域之一。它涉及到开发各种不同类型的网站和应用程序&#xff0c;从基本的静态页面到复杂的动态应用程序。本文将介绍 Web 程序设计的基础知识&#xff0c;包括 JavaScript、HTML、CSS 等方面的内容。 1、JavaScript JavaScript 是一种脚…

【Web】Dest0g3 520迎新赛 题解(全)

目录 phpdest EasyPHP SimpleRCE funny_upload EasySSTI middle PharPOP ezip NodeSoEasy Really Easy SQL&easysql EzSerial ljctr phpdest 尝试打pearcmd&#xff0c;但似乎没有写文件的权限 ?config-create/&file/usr/local/lib/php/pearcmd.php&a…

C++学习————第七天(初始化列表、static,友元,内部类)

今天已经是C学习第七天&#xff0c;希望这篇文章能够给大家带来更多的帮助&#xff0c;相应文章都放在C学习专栏里面。 C学习————第五天&#xff08;构造函数 析构函数 拷贝构造函数&#xff09;-CSDN博客 C学习————第六天 &#xff08;运算符重载 const成员 取地址&…

[渗透测试学习] Monitored-HackTheBox

Monitored-HackTheBox 信息搜集 nmap扫描一下端口 nmap -sV -sC -v --min-rate 1000 10.10.11.248扫描结果如下 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u3 (protocol 2.0) 80/tcp open http Apache httpd …

阿里巴巴拍立淘API让购物更智能:图片搜索商品,信息快速呈现,个性化推荐更精准

随着互联网的不断发展&#xff0c;电子商务已经成为人们日常生活中不可或缺的一部分。然而&#xff0c;传统的文本搜索方式在购物过程中往往存在信息不匹配、效率低下等问题。为了解决这些问题&#xff0c;阿里巴巴推出了拍立淘API&#xff0c;通过图片搜索商品的方式&#xff…

graphviz使用

安装 brew install graphviz测试 https://github.com/martisak/dotnets?tabreadme-ov-file

德鲁伊参数踩坑之路

上文说到 Druid德鲁伊参数调优实战&#xff0c;也正因此次优化&#xff0c;为后续问题埋下了伏笔 背景 2024/04/16日&#xff0c;业务反馈某个定时统计的数据未出来&#xff0c;大清早排查定位是其统计任务跑批失败&#xff0c;下面给一段伪代码 // 无事务执行 public void …

05 JavaScript学习:语法

JavaScript 是一种动态类型的脚本语言&#xff0c;广泛用于网页开发和构建交互式网页。JavaScript 的语法相对简单&#xff0c;但功能强大&#xff0c;它可以在客户端执行&#xff0c;并与HTML和CSS一起构建交互式的网页。 JavaScript 字面量 在 JavaScript 中&#xff0c;字…

吴恩达机器学习笔记:第 7 周-12支持向量机(Support Vector Machines)12.4-12.6

目录 第 7 周 12、 支持向量机(Support Vector Machines)12.4 核函数 112.5 核函数 212.6 使用支持向量机 第 7 周 12、 支持向量机(Support Vector Machines) 12.4 核函数 1 回顾我们之前讨论过可以使用高级数的多项式模型来解决无法用直线进行分隔的分类 问题&#xff1a; …

Octopus+: An RDMA-Enabled Distributed Persistent Memory File System——泛读笔记

TOS 2021 Paper 分布式元数据论文阅读笔记整理 问题 非易失性存储器&#xff08;NVM&#xff09;和远程直接存储器访问&#xff08;RDMA&#xff09;在存储和网络硬件中提供了极高的性能。然而&#xff0c;现有的分布式文件系统隔离了文件系统和网络层&#xff0c;而且分层的…

【C++】C++11右值引用

&#x1f440;樊梓慕&#xff1a;个人主页 &#x1f3a5;个人专栏&#xff1a;《C语言》《数据结构》《蓝桥杯试题》《LeetCode刷题笔记》《实训项目》《C》《Linux》《算法》 &#x1f31d;每一个不曾起舞的日子&#xff0c;都是对生命的辜负 目录 前言 1.什么是左值&&…