첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using ScottPlot;
using ScottPlot.Plottable;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Plot plot = new Plot(800, 600);

            double[] xValueArray = DataGen.Consecutive(20);
            double[] yValueArray = DataGen.Sin(20);

            ScatterPlotListDraggable scatterPlotListDraggable = new ScatterPlotListDraggable();

            scatterPlotListDraggable.AddRange(xValueArray, yValueArray);

            scatterPlotListDraggable.MarkerSize = 5;

            plot.Add(scatterPlotListDraggable);

            scatterPlotListDraggable.MovePointFunc = ProcessMovePoint;

            this.formsPlot.Reset(plot);

            this.formsPlot.Refresh();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 이동 포인트 처리하기 - ProcessMovePoint(xValueArray, yValueArray, index, coordinate)

        /// <summary>
        /// 이동 포인트 처리하기
        /// </summary>
        /// <param name="xValueArray">X 값 배열</param>
        /// <param name="yValueArray">Y 값 배열</param>
        /// <param name="index">인덱스</param>
        /// <param name="coordinate">좌표</param>
        /// <returns>좌표</returns>
        private Coordinate ProcessMovePoint(List<double> xValueArray, List<double> yValueArray, int index, Coordinate coordinate)
        {
            int leftIndex  = Math.Max(index - 1, 0                    );
            int rightIndex = Math.Min(index + 1, xValueArray.Count - 1);

            double newX = coordinate.X;

            newX = Math.Max(newX, xValueArray[leftIndex ]);
            newX = Math.Min(newX, xValueArray[rightIndex]);

            return new Coordinate(newX, coordinate.Y);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요