使用 Winform chart 绘制大数据量波形图,带缩放功能

我这的需求是使用Winform自带的chart控件,完成多路信号的显示,可以放大。缩小查看数据。好了。先上张图:

点击查看数据按钮,将生成的模拟信号数据显示出来。一共是52路信号,每个长度是1600。

用鼠标点击想要放大的区域:

放大后效果:

然后点击圆圈处即可返回。以下是控件的核心代码:

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 DemoSharp
{
    public partial class RealChart : Form
    {
        private List<double> dataQueue = new List<double>(10000);


        public RealChart()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 开始事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            InitChart();
            Random r = new Random();  
            for (int j = 0;j < 52; j++)
            {
                for (int i = 0; i < 1600; i++)
                {
                    this.chart1.Series[j].Points.AddXY((i + 1), r.Next(j, j + 2) + j);
                }
            }
        } 
        
        /// <summary>
        /// 初始化图表
        /// </summary>
        private void InitChart() {
            //定义图表区域
            this.chart1.ChartAreas.Clear();
            ChartArea chartArea1 = new ChartArea("C1");
            this.chart1.ChartAreas.Add(chartArea1);
            //定义存储和显示点的容器
            this.chart1.Series.Clear();
            for (int i = 0; i < 52;i++)
            {
                Series series1 = new Series(i.ToString());
                series1.ChartArea = "C1";
                this.chart1.Series.Add(series1);
                this.chart1.Series[i].Color = Color.Green;
                this.chart1.Series[i].ChartType = SeriesChartType.StepLine;
            }

            //设置图表显示样式
            this.chart1.ChartAreas[0].AxisX.ScaleView.Zoom(2,3);
            this.chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
            this.chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
            this.chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
            //将滚动内嵌到坐标轴中
            this.chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
            // 设置滚动条的大小
            this.chart1.ChartAreas[0].AxisX.ScrollBar.Size = 10;
            // 设置滚动条的按钮的风格,下面代码是将所有滚动条上的按钮都显示出来
            this.chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.All;
            this.chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = double.NaN;
            this.chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 2;
            this.chart1.ChartAreas[0].AxisY.Minimum = 0;
            this.chart1.ChartAreas[0].AxisY.Maximum =120;
            this.chart1.ChartAreas[0].AxisX.Interval = 200;
            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 = "数据显示";
            this.chart1.Titles[0].ForeColor = Color.RoyalBlue;
            this.chart1.Titles[0].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
            
        }
        
    }
}

以下是工程链接地址:https://download.csdn.net/download/chulijun3107/11349366

本意是不设积分的,奈何CSDN默认设置了。没有积分想要源码的留下邮箱吧。我看到后回。

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页