• 大小: 31KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: C#
  • 标签: C#  MSchart  动态显示  

资源简介

C# chart实时数据显示简单示例工程文件, 详细说明可以参看相关博文

资源截图

代码片段和文件信息

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;
using System.Windows.Forms.DataVisualization.Charting; //需要添加的命名空间

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

        System.Windows.Forms.Timer chartTimer = new System.Windows.Forms.Timer();

        private void InitChart()
        {
            DateTime time = DateTime.Now;
            chartTimer.Interval = 1000;
            chartTimer.Tick += chartTimer_Tick;
            chartDemo.DoubleClick += chartDemo_DoubleClick;

            Series series = chartDemo.Series[0];
            series.ChartType = SeriesChartType.Spline;

            chartDemo.ChartAreas[0].AxisX.Labelstyle.Format = “HH:mm:ss“;
            chartDemo.ChartAreas[0].AxisX.ScaleView.Size = 5;
            chartDemo.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
            chartDemo.ChartAreas[0].AxisX.ScrollBar.Enabled = true;

            chartTimer.Start();

        }

        void chartDemo_DoubleClick(object sender EventArgs e)
        {
            chartDemo.ChartAreas[0].AxisX.ScaleView.Size = 5;
            chartDemo.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
            chartDemo.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
            //throw new NotImplementedException();
        }

        void chartTimer_Tick(object sender EventArgs e)
        {
            Random ra = new Random();
            Series series = chartDemo.Series[0];
            series.Points.AddXY(DateTime.Now ra.Next(1 10));
            chartDemo.ChartAreas[0].AxisX.ScaleView.Position = series.Points.Count - 5;
            //throw new NotImplementedException();
        }

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        187  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\App.config

     文件      24224  2014-08-04 19:02  ChartRealTimeShow\ChartRealTimeShow\bin\Debug\ChartRealTimeShow.vshost.exe

     文件        187  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\bin\Debug\ChartRealTimeShow.vshost.exe.config

     文件        490  2010-03-17 22:39  ChartRealTimeShow\ChartRealTimeShow\bin\Debug\ChartRealTimeShow.vshost.exe.manifest

     文件       3882  2014-08-04 18:39  ChartRealTimeShow\ChartRealTimeShow\ChartRealTimeShow.csproj

     文件       2011  2014-08-04 18:58  ChartRealTimeShow\ChartRealTimeShow\Form1.cs

     文件       3185  2014-08-04 18:48  ChartRealTimeShow\ChartRealTimeShow\Form1.Designer.cs

     文件       5817  2014-08-04 18:58  ChartRealTimeShow\ChartRealTimeShow\Form1.resx

     文件       1020  2014-08-04 18:39  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7092  2014-08-04 18:39  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        529  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Program.cs

     文件       1378  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties\AssemblyInfo.cs

     文件       2886  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties\Resources.Designer.cs

     文件       5612  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties\Resources.resx

     文件       1104  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties\Settings.Designer.cs

     文件        249  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties\Settings.settings

     文件       1020  2014-08-04 18:39  ChartRealTimeShow\ChartRealTimeShow.sln

    ..A..H.     37376  2014-08-04 19:02  ChartRealTimeShow\ChartRealTimeShow.v12.suo

     目录          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\obj\Debug\TempPE

     目录          0  2014-08-04 19:02  ChartRealTimeShow\ChartRealTimeShow\bin\Debug

     目录          0  2014-08-04 19:02  ChartRealTimeShow\ChartRealTimeShow\obj\Debug

     目录          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\bin

     目录          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\obj

     目录          0  2014-08-04 18:38  ChartRealTimeShow\ChartRealTimeShow\Properties

     目录          0  2014-08-04 18:58  ChartRealTimeShow\ChartRealTimeShow

     目录          0  2014-08-04 18:39  ChartRealTimeShow

----------- ---------  ---------- -----  ----

............此处省略2个文件信息

评论

共有 条评论