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

news/2024/5/17 19:03:38

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.mrgr.cn/p/01426348

相关文章

用html画一个睡觉的熊动画

<!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><title>睡觉的熊动画</title><link rel"stylesheet" href"./style.css"> </head><body><div id"contain…

【重回王座】ChatGPT发布最新模型gpt-4-turbo-2024-04-09

今天&#xff0c;新版GPT-4 Turbo再次在大型模型排行榜上荣登榜首&#xff0c;成功超越了此前领先的Claude 3 Opus。另外&#xff0c;新模型在处理长达64k的上下文时&#xff0c;性能竟能够与旧版在处理26k上下文时的表现相当。 目前GPT-4 Turbo仅限于ChatGPT Plus的用户&…

Leetcode - 周赛393

目录 一&#xff0c;3114. 替换字符可以得到的最晚时间 二&#xff0c;3115. 素数的最大距离 三&#xff0c;3116. 单面值组合的第 K 小金额 四&#xff0c; 3117. 划分数组得到最小的值之和 一&#xff0c;3114. 替换字符可以得到的最晚时间 本题是一道模拟题&#xff0c;…

java spring boot 2 开发实战笔记

本案例是java sping boot 2.2.1 第一步搭建环境:安装依赖 由于我们公司项目是1.8 环境不能乱,我现在自己的电脑是1.8环境,所以本次整理的boot 代码 也只能用1.8 boot版本为:2.2.1,新建项目后,在xml 文件中复制上以下代码 xml配置,最精简运行起来的需要配置一个数据库…

【代码随想录】【动态规划】day51:● 309.最佳买卖股票时机含冷冻期 ● 714.买卖股票的最佳时机含手续费

股票含冷冻期 def maxProfit(self, prices):""":type prices: List[int]:rtype: int"""if len(prices)<1:return 0else:dp[[0]*2 for _ in range(len(prices))]dp[0][0]-prices[0]dp[0][1]0dp[1][0]max(dp[0][0],dp[0][1]-prices[1])dp[1][1]…

Github 2024-04-16Python开源项目日报 Top10

根据Github Trendings的统计,今日(2024-04-16统计)共有10个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Python项目10TypeScript项目1Vue项目1系统设计指南 创建周期:2507 天开发语言:Python协议类型:OtherStar数量:241693 个Fork数量:42010 次…

个人 Scrum Day 4

一、项目总结 昨天已完成的工作:食堂列表界面 今日计划完成工作:用户登录系统 工作中遇到的困难:使用新版微信小程序的api接口和设计登录弹窗。 二、代码签入 https://github.com/gdut-canteen/gdut-canteen/commit/79cb13c09bc60343e20561a989d3eaaf8dc7075f 三、运行部分截…

aaPanel面板和宝塔(BT)面板安装及命令

aaPanel面板和宝塔面板都是同一家公司在运营,只是aaPanel面板主要服务于海外客户,宝塔面板服务于本地客户。通常如果使用的是海外的服务器部署web环境,建议使用aaPanel面板。宝塔面板是一款基于 Web 的管理服务器的面板软件,它可以帮助用户方便地管理服务器的各种功能。面板…

租用境外服务器,越南服务器的优势有哪些

自从中国加入世界贸易组织之后&#xff0c;国内经济增加速度非常快&#xff0c;同时越来越多的人选择去东南亚国家发展&#xff0c;因为当地的中国人很多&#xff0c;所以中国企业在当地面临着更小的文化差异。东南亚地区也是最新的经济体&#xff0c;互联网正处于蓬勃发展的阶…

数据结构:线性表————单链表专题

&#x1f308;个人主页&#xff1a;小新_- &#x1f388;个人座右铭&#xff1a;“成功者不是从不失败的人&#xff0c;而是从不放弃的人&#xff01;”&#x1f388; &#x1f381;欢迎各位→点赞&#x1f44d; 收藏⭐️ 留言&#x1f4dd; &#x1f3c6;所属专栏&#xff1…

vue和react通用后台管理系统权限控制方案

1. 介绍 在任何企业级应用中&#xff0c;尤其是后台管理系统&#xff0c;权限控制是一个至关重要的环节。它确保了系统资源的安全性&#xff0c;防止非法访问和操作&#xff0c;保障业务流程的正常进行。本文件将详细解析后台管理系统中的权限控制机制及其实施策略。 那么权限…

使用Docker部署开源建站工具—Halo,并实现个人博客公网访问

目录 推荐 前言 1. Docker部署Halo 1.1 检查Docker版本 如果未安装Docker可参考&#xff1a; 已安装Docker步骤&#xff1a; 1.2 在Docker中部署Halo 2. Linux安装Cpolar 2.1 打开服务器防火墙 2.2 安装cpolar内网穿透 3. 配置Halo个人博客公网地址 4. 固定Halo公网…

如何使用XSSFWorkbook读取文本薄?

本篇文章暂不对XSSFWorkbook类进行解析和说明,仅附有实现代码。 如果文中阐述不全或不对的,多多交流。【版权声明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://www.cnblogs.com/cnb-yuchen/p/18146625 出自【进步*于辰的博客】1、文件兼容类型。 // 兼…

GAMES101 作业7 踩坑指南

首先回顾路径追踪的原理,如下图基本思想 wo是射向眼镜(相机)的光线,包含来自光源的直接光照ws,来自其他物体的间接光照wi两部分。 在实现path tracing时,我们考虑的是黄色线的方向,即光线从相机射向p点(实际上是从p点射向相机),然后通过多次随机采样从p点射出(实际上…

MoJoCo 入门教程(七)XML 参考

系列文章目录 前言 表格第二列中的符号含义如下&#xff1a; ! 必填元素&#xff0c;只能出现一次 ? 可选元素&#xff0c;只能出现一次 * 可选元素&#xff0c;可多次出现 R 可选元素&#xff0c;可递归出现多次 一、简介 本章是 MuJoCo 中使用的 MJCF 建模语言的参考手册。…

【继承】菱形继承以及虚拟菱形继承

文章目录 什么叫菱形继承菱形继承带来的问题 虚拟继承虚拟继承的内存布局总结&#xff1a; 关于继承和组合组合的优势代码复用最常见的几种手段有&#xff1a;继承的合理使用场景总结 什么叫菱形继承 菱形继承是多继承的一种特殊情况。什么叫多继承呢&#xff1f; 多继承又称多…

实验一原型设计-汽水音乐app

一、对比墨刀、Axure、Mockplus等原型设计工具的各自的适用领域及优缺点墨刀 • 适用领域:主要专注于app原型设计,适合高保真原型、复杂多交互项目以及安卓/ios端项目。 • 优点:操作效率高,易于上手,特别适合设计移动应用的交互原型。 • 缺点:在后台和网页设计方面稍显…

数据库的物化视图

数据库的物化视图 数据库的物化视图(Materialized View)是一种预先计算和存储的查询结果集,可以提高查询性能和减少查询开销。与普通视图不同,物化视图是实际存储在磁盘上的表,而不是只是一个查询语句。物化视图可以在需要时更新,以保持其数据的实时性。 优点提高查询性能…

LCD显示屏 --- 介绍

LCD数据手册关键信息提取 LCD说明 LCD 即 液晶显示器,依据驱动方式可以分为静态驱动,简单矩阵驱动,主动矩阵驱动三种,其中简单矩阵分为TN和STN两种,主动矩阵则以薄膜式晶体管(TFT)为主。TFT LCD的现实质量是最佳的,从硬件角度看,一块LCD屏显示图像不但需要LCD驱动器,还…