C# winform使用scottplot图表控件快速入门设置XY轴缩放

Hello大家好我是开箱测评小汪,在C#项目开发中使用图表控件,有时候我们希望放大或缩小图表控件来看数据细节和整体数据情况。所有本期课程将带介绍Scottplot图表控件如何来实现这个功能。

 

本期课程的要达到的目的:

  1. 设置鼠标管轮缩放进行缩放
  2. 设置鼠标右键长按进行拖放
  3. X轴锁定缩放
  4. Y轴锁定缩放

环境:

Visual Studio 2019   .net5.0

项目中拖拽出三个复选框,然后为每个复选框添加CheckedChanged事件

程序源码:

using ScottPlot;
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;

namespace Scottplot_01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var plt = formsPlot1.Plot;

            // sample data
            //X轴数据
            double[] xs = DataGen.Consecutive(51);

            //Y轴数据
            double[] sin = DataGen.Sin(51);
            double[] cos = DataGen.Cos(51);

            // 2条曲线
            plt.AddScatter(xs, sin);
            plt.AddScatter(xs, cos);

            // plot参数设置
            plt.Title("标题");
            plt.XLabel("X轴");
            plt.YLabel("Y轴");


            //缩放进行配置
           
            formsPlot1.Refresh();
        }


        
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            //鼠标右键拖拽缩放
            this.formsPlot1.Configuration.RightClickDragZoom = this.cbZoomable.Checked;

            //鼠标管轮缩放
            this.formsPlot1.Configuration.ScrollWheelZoom = this.cbZoomable.Checked;
        }

        private void cbLockHorizontal_CheckedChanged(object sender, EventArgs e)
        {
            //锁定水平缩放
            this.formsPlot1.Configuration.LockHorizontalAxis = this.cbLockHorizontal.Checked;
        }

        private void cbLockVertical_CheckedChanged(object sender, EventArgs e)
        {
            //锁定垂直缩放
            this.formsPlot1.Configuration.LockVerticalAxis = this.cbLockVertical.Checked;
        }
    

    }
}

      本期教程为项目scottplot图表控件增加了对图表进行缩放,X轴锁定缩放,Y轴锁定缩放的功能,但是光有这些内容还是不能满足我们的要求,下期我将为项目增加十字光标尺功能。感谢各位朋友持续关注我的文章更新。欢迎各位朋友点赞、关注、评论谢谢!

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值