使用 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

资源设置为0C币了。可以直接去下载了。喜欢的给我点个赞或关注。

评论 126
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

楚楚3107

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值