• 大小: 59KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-27
  • 语言: C#
  • 标签: c#  

资源简介

实现柱状图的实时数据显示功能,采用.NET Frame4.0技术,,使用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.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
           

            string str = ““;
            for (int i = 0; i < 4; i++)
            {
                str = “Series“ + (i + 1).ToString();
                Series series = chart1.Series.Add(str);
                series.ChartArea = “ChartArea1“;
                //series.ChartType = SeriesChartType.Spline;
                series.XValueType = ChartValueType.Time;
                series.BorderWidth = 2;

                // 数据点标记样式
                series.Markerstyle = Markerstyle.Circle;
                series.MarkerSize = 4;
                series.MarkerColor = Color.Magenta;
                series.MarkerBorderColor = Color.Red;
                series.MarkerBorderWidth = 1;

                //图例中项的文本

                switch(i){
                    case 0: series.LegendText = “温度“; break;
                    case 1: series.LegendText = “光照“; break;
                    case 2: series.LegendText = “有害气体“; break;
                    case 3: series.LegendText = “二氧化碳“; break;
                }

          }



        }


        private void button1_Click(object sender EventArgs e)
        {
            //校验数据是否正确

           
            
 
                
            }




        private void addData(Series series double d)
        {
            //添加数据
            //判断数据点的个数,进行数个的控制    
            int intTemp = series.Points.Count();
            if (intTemp > 5)
            {
                //删除最前面的点

                series.Points.Remove(series.Points.First());
               // series.Points.Add(d);
                series.Points.AddXY(DateTime.Now.ToLongTimeString().ToString() d);
            }
            else
            {
                //series.Points.Add(d);
                series.Points.AddXY(DateTime.Now.ToLongTimeString().ToString() d);
            }

        }


        private void timer1_Tick(object sender EventArgs e)
        {
            /******************数据接收区******************/
            double[] dArray = new double[4];
            Random random = new Random();
            for (int i = 0; i < 4; i++ )
            {
                double tempD = random.NextDouble();
                int tempI = random.Next(1 100);
                double temp = tempD + tempI;
                dArray[i] = temp;
            }
            /******************数据接收区******************/

            /******************给曲线图添加数据点******************/
            try
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-05-03 09:25  C# 动态柱状图\
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\
     文件         914  2013-04-26 09:19  C# 动态柱状图\WindowsFormsApplication1.sln
     文件       27136  2013-05-02 17:45  C# 动态柱状图\WindowsFormsApplication1.suo
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\bin\
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\bin\Debug\
     文件       13312  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件       36352  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     文件       11600  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
     文件         490  2010-03-17 22:39  C# 动态柱状图\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\bin\Release\
     文件        4656  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\Form1.cs
     文件        8876  2013-04-28 08:48  C# 动态柱状图\WindowsFormsApplication1\Form1.Designer.cs
     文件        6011  2013-04-28 08:48  C# 动态柱状图\WindowsFormsApplication1\Form1.resx
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\obj\
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\obj\x86\
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\
     文件        5226  2013-04-26 13:58  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6500  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1112  2013-04-28 08:48  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog
     文件        3756  2013-04-28 08:48  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog
     文件        8683  2013-04-27 08:44  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\ResolveAssemblyReference.cache
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\TempPE\
     文件        2561  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
     文件       13312  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
     文件         180  2013-04-28 08:48  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
     文件       36352  2013-05-03 09:24  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
     文件         180  2013-04-27 10:49  C# 动态柱状图\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
     文件         505  2013-04-26 09:19  C# 动态柱状图\WindowsFormsApplication1\Program.cs
     目录           0  2013-05-03 09:25  C# 动态柱状图\WindowsFormsApplication1\Properties\
     文件        1404  2013-04-26 09:19  C# 动态柱状图\WindowsFormsApplication1\Properties\AssemblyInfo.cs
............此处省略5个文件信息

评论

共有 条评论