资源简介

使用.net 4.0 Chart控件实现动态的曲线图,即随时间变化而滚动的曲线图,同时绘制了两条曲线,以及水平线(用于警戒值、水平值、阀值等)。一开始要做这人需求的时间发现两眼摸黑,网上查了很多资料,要么是其他插件,要么就是假大空,折腾了很久,还是从MSDN上取经,自己研究着做,终于实现了所有的需求。贡献出来,希望给大家带来帮助,少走一点弯路。

资源截图

代码片段和文件信息

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.Windows.Forms.DataVisualization.Charting;

namespace DynamicChartDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Timer timer1 = new Timer();
        private Timer timer2 = new Timer();
        private DataTable dt1 = new DataTable();

        private DateTime dtTime = new DateTime();
        private void Form1_Load(object sender EventArgs e)
        {
            this.chart1.titles.Add(“动态曲线图DEMO“);
            this.chart1.ChartAreas[0].AxisX.title = “时间“;
            this.chart1.ChartAreas[0].AxisY.title = “數值“;

            this.chart1.ChartAreas[0].AxisX.Interval = 5;
            this.chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart1.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart1.ChartAreas[0].AxisY.Interval = 0.5;
            this.chart1.ChartAreas[0].AxisY.Maximum = 10;
            this.chart1.ChartAreas[0].AxisY.Minimum = 1;
            //this.chart1.ChartAreas[0].AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.FixedCount;
            //this.chart1.ChartAreas[0].AxisY.IsStartedFromZero = false;
            this.chart1.Series.Add(“series1“);
            this.chart1.Series.Add(“series2“);

            //使图标刚开始的时候是空的,随着时间的推移才逐渐画满,可以在初始化的时候填几个Y坐标为0的点:
            for (int i = 0; i < 60 ; i++)
            {
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                dp.SetValueXY(DateTime.Now.AddSeconds(-60 + i).ToString(“HH:mm:ss“) 0);
                this.chart1.Series[0].Points.Add(dp);

                System.Windows.Forms.DataVisualization.Charting.DataPoint dp1 = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                dp1.SetValueXY(DateTime.Now.AddSeconds(-60 + i).ToString(“HH:mm:ss“) 0);
                this.chart1.Series[1].Points.Add(dp1);
            }

            chart1.Series[0].IsValueShownAsLabel = true;
            this.chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.SplineArea;
            this.chart1.Series[0].BorderDashstyle = System.Windows.Forms.DataVisualization.Charting.ChartDashstyle.Solid;
            this.chart1.Series[0].BorderWidth = 3;
            this.chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
            this.chart1.Series[1].BorderDashstyle = System.Windows.Forms.DataVisualization.Charting.ChartDashstyle.DashDot;
       

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-29 14:35  DynamicChartDemo\
     目录           0  2013-11-29 14:35  DynamicChartDemo\bin\
     目录           0  2013-11-29 14:37  DynamicChartDemo\bin\Debug\
     文件       12800  2013-11-29 15:33  DynamicChartDemo\bin\Debug\DynamicChartDemo.exe
     文件       26112  2013-11-29 15:33  DynamicChartDemo\bin\Debug\DynamicChartDemo.pdb
     文件       11600  2013-11-29 15:43  DynamicChartDemo\bin\Debug\DynamicChartDemo.vshost.exe
     文件         490  2010-03-17 22:39  DynamicChartDemo\bin\Debug\DynamicChartDemo.vshost.exe.manifest
     目录           0  2013-11-29 14:35  DynamicChartDemo\bin\Release\
     文件        3759  2013-11-29 14:37  DynamicChartDemo\DynamicChartDemo.csproj
     文件        8331  2013-11-29 15:33  DynamicChartDemo\Form1.cs
     文件        2802  2013-11-29 11:44  DynamicChartDemo\Form1.Designer.cs
     文件        5817  2013-11-29 11:44  DynamicChartDemo\Form1.resx
     目录           0  2013-11-27 14:35  DynamicChartDemo\obj\
     目录           0  2013-11-27 14:35  DynamicChartDemo\obj\x86\
     目录           0  2013-11-29 15:33  DynamicChartDemo\obj\x86\Debug\
     文件        2152  2013-11-27 14:35  DynamicChartDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6412  2013-11-29 15:33  DynamicChartDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         904  2013-11-29 15:43  DynamicChartDemo\obj\x86\Debug\DynamicChartDemo.csproj.FileListAbsolute.txt
     文件       12800  2013-11-29 15:33  DynamicChartDemo\obj\x86\Debug\DynamicChartDemo.exe
     文件         180  2013-11-29 14:38  DynamicChartDemo\obj\x86\Debug\DynamicChartDemo.Form1.resources
     文件       26112  2013-11-29 15:33  DynamicChartDemo\obj\x86\Debug\DynamicChartDemo.pdb
     文件         180  2013-11-29 14:38  DynamicChartDemo\obj\x86\Debug\DynamicChartDemo.Properties.Resources.resources
     文件         314  2013-11-29 14:38  DynamicChartDemo\obj\x86\Debug\GenerateResource.read.1.tlog
     文件        1400  2013-11-29 14:38  DynamicChartDemo\obj\x86\Debug\GenerateResource.write.1.tlog
     文件        8661  2013-11-27 15:41  DynamicChartDemo\obj\x86\Debug\ResolveAssemblyReference.cache
     目录           0  2013-11-27 14:35  DynamicChartDemo\obj\x86\Debug\TempPE\
     文件         508  2013-11-27 14:35  DynamicChartDemo\Program.cs
     目录           0  2013-11-27 14:35  DynamicChartDemo\Properties\
     文件        1444  2013-11-27 14:35  DynamicChartDemo\Properties\AssemblyInfo.cs
     文件        2861  2013-11-27 14:35  DynamicChartDemo\Properties\Resources.Designer.cs
     文件        5612  2013-11-27 14:35  DynamicChartDemo\Properties\Resources.resx
............此处省略2个文件信息

评论

共有 条评论