• 大小: 88KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-09
  • 语言: C#
  • 标签: C#  chart  

资源简介

C#中以时间作为chart的X坐标轴间隔,波形图chart的X轴坐标为时间(ms),

资源截图

代码片段和文件信息

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;   //与chart相关的引用
using System.Threading;

namespace testChartWithTime
{
    public partial class Form1 : Form
    {
        private DateTime minValue maxValue;    //横坐标最小和最大值

        private Random rand = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            minValue = DateTime.Now;          //x轴最小刻度 
            maxValue = minValue.AddSeconds(1); //X轴最大刻度比最小刻度大1秒
            chart1.ChartAreas[0].AxisX.Labelstyle.Format = “HH:mm:ss.fff“;         //毫秒格式: hh:mm:ss.fff ,后面几个f则保留几位毫秒小数,此时要注意轴的最大值和最小值不要差太大
            chart1.ChartAreas[0].AxisX.Labelstyle.IntervalType = DateTimeIntervalType.Milliseconds;
            chart1.ChartAreas[0].AxisX.Labelstyle.Interval = 200;               //坐标值间隔200 ms
            chart1.ChartAreas[0].AxisX.Labelstyle.IsEndLabelVisible = false;   //防止X轴坐标跳跃
            chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Milliseconds;
            chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 200;

            chart1.ChartAreas[0].AxisX.Minimum = minValue.ToOADate();
            chart1.ChartAreas[0].AxisX.Maximum = maxValue.ToOADate();
            chart1.Series.Clear();

            Series newSeries = new Series(“Series1“);
            newSeries.ChartType = SeriesChartType.Line;
            newSeries.BorderWidth = 1;
            newSeries.Color = Color.FromArgb(0 0 255);
            newSeries.XValueType = ChartValueType.DateTime;
            chart1.Series.Add(newSeries);
            timer1.Interval = 200;

            chart1.Series[0].Points.AddXY(DateTime.Now.ToOADate() 10);
            Thread.Sleep(200);
            chart1.Series[0].Points.AddXY(DateTime.Now.ToOADate() 5);
            Thread.Sleep(200);
            chart1.Series[0].Points.AddXY(DateTime.Now.ToOADate() 15);
            Thread.Sleep(200);
            chart1.Series[0].Points.AddXY(DateTime.Now.ToOADate() 10);
            Thread.Sleep(1000);
            chart1.Series[0].Points.AddXY(DateTime.Now.ToOADate() 15);
            Thread.Sleep(100);
            chart1.ChartAreas[0].AxisX.Maximum = DateTime.Now.ToOADate();
            
        }

        public void AddNewPoint(DateTime timeStamp System.Windows.Forms.DataVisualization.Charting.Series ptSeries)
        {
            // Add new data point to its series.
            ptSeries.Points.AddXY(timeStamp.ToOADate() rand.Next(5 20));
            // remove all points from the source series older than 1 seconds.
            double removeBefore = timeStamp.AddSeconds((double)(1) * (-1)).ToOADate();

            //remove oldest valu

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

     文件      18944  2018-09-20 09:51  testChartWithTime\testChartWithTime\bin\Debug\testChartWithTime.exe

     文件      30208  2018-09-20 09:51  testChartWithTime\testChartWithTime\bin\Debug\testChartWithTime.pdb

     文件      11600  2018-09-21 08:52  testChartWithTime\testChartWithTime\bin\Debug\testChartWithTime.vshost.exe

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

     文件       4188  2018-09-20 10:18  testChartWithTime\testChartWithTime\Form1.cs

     文件       4869  2018-09-20 09:50  testChartWithTime\testChartWithTime\Form1.Designer.cs

     文件       6184  2018-09-20 09:50  testChartWithTime\testChartWithTime\Form1.resx

     文件       6272  2018-09-20 15:00  testChartWithTime\testChartWithTime\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6638  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      88576  2018-08-23 10:51  testChartWithTime\testChartWithTime\obj\x86\Debug\Interop.ADODB.dll

     文件      23040  2018-08-23 10:51  testChartWithTime\testChartWithTime\obj\x86\Debug\Interop.ADOX.dll

     文件       1881  2018-09-21 08:52  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.csproj.FileListAbsolute.txt

     文件        975  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.csproj.GenerateResource.Cache

     文件        835  2018-08-23 10:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.csproj.ResolveComReference.cache

     文件      18944  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.exe

     文件        180  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.Form1.resources

     文件      30208  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.pdb

     文件        180  2018-09-20 09:51  testChartWithTime\testChartWithTime\obj\x86\Debug\testChartWithTime.Properties.Resources.resources

     文件        498  2018-08-23 09:24  testChartWithTime\testChartWithTime\Program.cs

     文件       1384  2018-08-23 09:24  testChartWithTime\testChartWithTime\Properties\AssemblyInfo.cs

     文件       2886  2018-08-23 09:24  testChartWithTime\testChartWithTime\Properties\Resources.Designer.cs

     文件       5612  2018-08-23 09:24  testChartWithTime\testChartWithTime\Properties\Resources.resx

     文件       1104  2018-08-23 09:24  testChartWithTime\testChartWithTime\Properties\Settings.Designer.cs

     文件        249  2018-08-23 09:24  testChartWithTime\testChartWithTime\Properties\Settings.settings

     文件       7828  2018-08-23 10:51  testChartWithTime\testChartWithTime\saveAccessFile.cs

     文件       4516  2018-09-20 09:51  testChartWithTime\testChartWithTime\testChartWithTime.csproj

     文件        893  2018-08-23 09:24  testChartWithTime\testChartWithTime.sln

    ..A..H.     53248  2018-09-21 08:52  testChartWithTime\testChartWithTime.suo

     目录          0  2018-08-23 09:24  testChartWithTime\testChartWithTime\obj\x86\Debug\TempPE

     目录          0  2018-09-20 15:00  testChartWithTime\testChartWithTime\obj\x86\Debug

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

评论

共有 条评论