实时显示折线图
作者:互联网
使用微软Chart控件,实时显示温度数据。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;
namespace 实时监控
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitChart();
}
//初始化
private void InitChart()
{
//设置series的样式
Series series = chart1.Series[0];
series.ChartType = SeriesChartType.Line;
//设置X轴的样式
chart1.ChartAreas[0].AxisX.ScaleView.Size = 5;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
//设置Y轴的样式
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 100;
}
//计时器
private void timer1_Tick(object sender, EventArgs e)
{
DateTime time = DateTime.Now;
//随机数作为数据源
Random random = new Random();
Series series1 = chart1.Series[0];
series1.Points.AddXY(time, random.Next(1, 100));
//让轴视图显示在当前进度条位置
chart1.ChartAreas[0].AxisX.ScaleView.Position = series1.Points.Count - 5;
}
//按钮 开始
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
//按钮 停止
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
标签:显示,void,AxisX,System,实时,chart1,ChartAreas,折线图,using 来源: https://blog.csdn.net/NickStudent/article/details/110141893