ScottPlot图标控件的使用

效果图在这里插入图片描述

控件获取方法

Nugget
ScottPlot.WinForms

参考代码

Form1.Designer.cs


namespace ScottplotDemo
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.formsPlot1 = new ScottPlot.FormsPlot();
            this.cbZoomable = new System.Windows.Forms.CheckBox();
            this.cbLockHorizontal = new System.Windows.Forms.CheckBox();
            this.cbLockVertical = new System.Windows.Forms.CheckBox();
            this.CrosshaircheckBox = new System.Windows.Forms.CheckBox();
            this.PixelLabel = new System.Windows.Forms.Label();
            this.XCoordinateLabel = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // formsPlot1
            // 
            this.formsPlot1.Location = new System.Drawing.Point(5, 79);
            this.formsPlot1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
            this.formsPlot1.Name = "formsPlot1";
            this.formsPlot1.Size = new System.Drawing.Size(785, 428);
            this.formsPlot1.TabIndex = 0;
            this.formsPlot1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.formsPlot1_MouseMove);
            // 
            // cbZoomable
            // 
            this.cbZoomable.AutoSize = true;
            this.cbZoomable.Location = new System.Drawing.Point(12, 30);
            this.cbZoomable.Name = "cbZoomable";
            this.cbZoomable.Size = new System.Drawing.Size(96, 16);
            this.cbZoomable.TabIndex = 1;
            this.cbZoomable.Text = "锁定鼠标缩放";
            this.cbZoomable.UseVisualStyleBackColor = true;
            this.cbZoomable.CheckedChanged += new System.EventHandler(this.cbZoomable_CheckedChanged);
            // 
            // cbLockHorizontal
            // 
            this.cbLockHorizontal.AutoSize = true;
            this.cbLockHorizontal.Location = new System.Drawing.Point(119, 30);
            this.cbLockHorizontal.Name = "cbLockHorizontal";
            this.cbLockHorizontal.Size = new System.Drawing.Size(96, 16);
            this.cbLockHorizontal.TabIndex = 1;
            this.cbLockHorizontal.Text = "锁定水平缩放";
            this.cbLockHorizontal.UseVisualStyleBackColor = true;
            this.cbLockHorizontal.CheckedChanged += new System.EventHandler(this.cbLockHorizontal_CheckedChanged);
            // 
            // cbLockVertical
            // 
            this.cbLockVertical.AutoSize = true;
            this.cbLockVertical.Location = new System.Drawing.Point(119, 52);
            this.cbLockVertical.Name = "cbLockVertical";
            this.cbLockVertical.Size = new System.Drawing.Size(96, 16);
            this.cbLockVertical.TabIndex = 1;
            this.cbLockVertical.Text = "锁定垂直缩放";
            this.cbLockVertical.UseVisualStyleBackColor = true;
            this.cbLockVertical.CheckedChanged += new System.EventHandler(this.cbLockVertical_CheckedChanged);
            // 
            // CrosshaircheckBox
            // 
            this.CrosshaircheckBox.AutoSize = true;
            this.CrosshaircheckBox.Location = new System.Drawing.Point(248, 30);
            this.CrosshaircheckBox.Name = "CrosshaircheckBox";
            this.CrosshaircheckBox.Size = new System.Drawing.Size(72, 16);
            this.CrosshaircheckBox.TabIndex = 1;
            this.CrosshaircheckBox.Text = "十字光标";
            this.CrosshaircheckBox.UseVisualStyleBackColor = true;
            this.CrosshaircheckBox.CheckedChanged += new System.EventHandler(this.cbLockHorizontal_CheckedChanged);
            // 
            // PixelLabel
            // 
            this.PixelLabel.AutoSize = true;
            this.PixelLabel.Location = new System.Drawing.Point(3, 527);
            this.PixelLabel.Name = "PixelLabel";
            this.PixelLabel.Size = new System.Drawing.Size(29, 12);
            this.PixelLabel.TabIndex = 2;
            this.PixelLabel.Text = "null";
            // 
            // XCoordinateLabel
            // 
            this.XCoordinateLabel.AutoSize = true;
            this.XCoordinateLabel.Location = new System.Drawing.Point(246, 527);
            this.XCoordinateLabel.Name = "XCoordinateLabel";
            this.XCoordinateLabel.Size = new System.Drawing.Size(29, 12);
            this.XCoordinateLabel.TabIndex = 2;
            this.XCoordinateLabel.Text = "null";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 548);
            this.Controls.Add(this.XCoordinateLabel);
            this.Controls.Add(this.PixelLabel);
            this.Controls.Add(this.cbLockVertical);
            this.Controls.Add(this.CrosshaircheckBox);
            this.Controls.Add(this.cbLockHorizontal);
            this.Controls.Add(this.cbZoomable);
            this.Controls.Add(this.formsPlot1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private ScottPlot.FormsPlot formsPlot1;
        private System.Windows.Forms.CheckBox cbZoomable;
        private System.Windows.Forms.CheckBox cbLockHorizontal;
        private System.Windows.Forms.CheckBox cbLockVertical;
        private System.Windows.Forms.CheckBox CrosshaircheckBox;
        private System.Windows.Forms.Label PixelLabel;
        private System.Windows.Forms.Label XCoordinateLabel;
    }
}


Form1

using ScottPlot;
using ScottPlot.Plottable;
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 ScottplotDemo
{
    public partial class Form1 : Form
    {
        private readonly Crosshair Crosshair;
        public Form1()
        {
            InitializeComponent();
            var plt = formsPlot1.Plot;

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

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

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

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

            //添加十字光标线
            Crosshair = this.formsPlot1.Plot.AddCrosshair(0.0, 0.0);
            formsPlot1.Refresh();
        }

        private void cbZoomable_CheckedChanged(object sender, EventArgs e)
        {
            //鼠标右键拖拽缩放
            formsPlot1.Configuration.RightClickDragZoom = !cbZoomable.Checked;
            //鼠标管轮缩放
            formsPlot1.Configuration.ScrollWheelZoom = !cbZoomable.Checked;
        }

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

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

        private void formsPlot1_MouseMove(object sender, MouseEventArgs e)
        {
            if (CrosshaircheckBox.Checked)
            {
                ValueTuple<double, double> mouseCoordinates = this.formsPlot1.GetMouseCoordinates();
                double coordinateX = mouseCoordinates.Item1;
                double coordinateY = mouseCoordinates.Item2;
                PixelLabel.Text = $"{e.X.ToString("0.00000")},{e.Y.ToString("0.00000")}";
                XCoordinateLabel.Text = $"{coordinateX.ToString("0.00000000")},{coordinateY.ToString("0.00000000")}";
                Crosshair.X = coordinateX;
                Crosshair.Y = coordinateY;
            }

            //this.XPixelLabel.Location = new System.Drawing.Point(e.X, e.Y);

            //如果设置十字光标线为不显示数值就不显示了
            if (!CrosshaircheckBox.Checked)
            {
                this.PixelLabel.Text = "";
                this.XCoordinateLabel.Text = "";
            }

            this.formsPlot1.Refresh(false, false);
        }
    }
}

注意事项

ScottPlot开源库的依赖库,避免与原有项目中依赖库冲突
如:“System.Threading.dll”等都是.net常用库

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值