zoukankan      html  css  js  c++  java
  • C#话曲线图

    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 WindowsFormsApp6
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            //自定义函数
    
            private Queue<double> dataQueue = new Queue<double>(100);
    
            private int curValue = 0;
    
            private int num = 1;//每次删除增加几个点
    
    
            /// <summary>
            /// 初始化图表
            /// </summary>
            private void InitChart()
            {
                //定义图表区域
                this.chart1.ChartAreas.Clear();
                ChartArea chartArea1 = new ChartArea("C1");
                this.chart1.ChartAreas.Add(chartArea1);
                //定义存储和显示点的容器
                this.chart1.Series.Clear();
                Series series1 = new Series("S1");
                series1.ChartArea = "C1";
                this.chart1.Series.Add(series1);
                //设置图表显示样式
                this.chart1.ChartAreas[0].AxisY.Minimum = 0;
                this.chart1.ChartAreas[0].AxisY.Maximum = 100;
                this.chart1.ChartAreas[0].AxisX.Interval = 1;
                this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
                this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
                //设置标题
                this.chart1.Titles.Clear();
                this.chart1.Titles.Add("S01");
                this.chart1.Titles[0].Text = "XXX显示";
                this.chart1.Titles[0].ForeColor = Color.RoyalBlue;
                this.chart1.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
                //设置图表显示样式
                this.chart1.Series[0].Color = Color.Red;
    
                this.chart1.Series[0].ChartType = SeriesChartType.Line;
                this.chart1.Series[0].Points.Clear();
            }
            private void UpdateQueueValue()
            {
    
                if (dataQueue.Count > 100)
                {
                    //先出列
                    for (int i = 0; i < num; i++)
                    {
                        dataQueue.Dequeue();
                    }
                }
                
                    Random r = new Random();
                    for (int i = 0; i < num; i++)
                    {
                        dataQueue.Enqueue(r.Next(0, 100));
                    }
               
               
            }
    
    
    
    
    
    
    
            private void Form1_Load(object sender, EventArgs e)
            {
                InitChart();
                this.timer1.Start();
    
            }
    
    
    
       
    
            private void timer1_Tick_1(object sender, EventArgs e)
            {
                UpdateQueueValue();
                this.chart1.Series[0].Points.Clear();
                for (int i = 0; i < dataQueue.Count; i++)
                {
                    this.chart1.Series[0].Points.AddXY((i + 1), dataQueue.ElementAt(i));
                }
    
            }
        }
    }
  • 相关阅读:
    STL应用 map poj 2418
    STL应用 set hdu 1412
    STL应用 deque hdu 6375
    STL应用 queue poj 1915
    STL应用 map HDU 3527
    算法训练营 入门篇 STL应用 vector HDU 3527
    算法训练营:海量图解+竞赛刷题(入门篇)刷题, 算法基础知识点讲解与练习
    BFS 遍历例子
    【知识】MySQL索引原理及慢查询优化
    【MySQL优化】——看懂explain
  • 原文地址:https://www.cnblogs.com/WP-WangPin/p/13911891.html
Copyright © 2011-2022 走看看