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

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Drawing;
using System.Windows.Forms;

using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;

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

        #region Field

        /// <summary>
        /// 수직 축
        /// </summary>
        private Axis vertAxis;

        /// <summary>
        /// 수평 축
        /// </summary>
        private Axis horizAxis;

        /// <summary>
        /// 상단 라인
        /// </summary>
        private Line topLine;

        /// <summary>
        /// 하단 라인
        /// </summary>
        private HorizLine bottomLine;

        /// <summary>
        /// 상단 라인 최근접 포인트
        /// </summary>
        private NearestPoint topLineNearestPoint;

        /// <summary>
        /// 하단 라인 최근접 포인트
        /// </summary>
        private NearestPoint bottomLineNearestPoint;

        /// <summary>
        /// 주석 1
        /// </summary>
        private Annotation topLineAnnotation;

        /// <summary>
        /// 주석 2
        /// </summary>
        private Annotation bottomLineAnnotation;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            this.topLineDirectionComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

            this.topLineDirectionComboBox.Items.Add("수평"     );
            this.topLineDirectionComboBox.Items.Add("수직"     );
            this.topLineDirectionComboBox.Items.Add("수평/수직");

            this.topLineDirectionComboBox.SelectedIndex = 0;

            this.bottomLineDirectionComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

            this.bottomLineDirectionComboBox.Items.Add("수평"     );
            this.bottomLineDirectionComboBox.Items.Add("수직"     );
            this.bottomLineDirectionComboBox.Items.Add("수평/수직");

            this.bottomLineDirectionComboBox.SelectedIndex = 1;

            Text = "NearestPoint 클래스 : Direction 속성을 사용해 최근접 포인트 구하기";

            this.tChart.Panel.Pen                = new ChartPen(Color.Black);
            this.tChart.Axes.Bottom.Grid.Visible = false;
            this.tChart.Axes.Left.StartPosition  = 0;
            this.tChart.Axes.Left.EndPosition    = 45;

            this.horizAxis = new Axis(true, false, this.tChart.Chart);

            this.horizAxis.PositionUnits    = PositionUnits.Percent;
            this.horizAxis.RelativePosition = 55;
            this.horizAxis.Grid.Visible     = false;

            this.tChart.Axes.Custom.Add(horizAxis);

            this.vertAxis = new Axis(false, false, this.tChart.Chart);

            this.vertAxis.StartPosition = 55;
            this.vertAxis.EndPosition   = 100;

            this.tChart.Axes.Custom.Add(vertAxis);

            this.topLine = new Line(this.tChart.Chart);

            this.topLine.HorizAxis       = HorizontalAxis.Custom;
            this.topLine.CustomHorizAxis = horizAxis;
            this.topLine.VertAxis        = VerticalAxis.Left;

            this.topLine.FillSampleValues();

            this.bottomLine = new HorizLine(this.tChart.Chart);

            this.bottomLine.HorizAxis      = HorizontalAxis.Bottom;
            this.bottomLine.VertAxis       = VerticalAxis.Custom;
            this.bottomLine.CustomVertAxis = vertAxis;

            this.bottomLine.FillSampleValues();

            this.topLineNearestPoint = new NearestPoint(this.tChart.Chart);

            this.topLineNearestPoint.Size        = 5;
            this.topLineNearestPoint.Brush.Color = bottomLine.Color;
            this.topLineNearestPoint.Direction   = NearestPointDirection.Horizontal;
            this.topLineNearestPoint.DrawLine    = false;
            this.topLineNearestPoint.Series      = this.topLine;

            this.bottomLineNearestPoint = new NearestPoint(this.tChart.Chart);

            this.bottomLineNearestPoint.Size        = 5;
            this.bottomLineNearestPoint.Brush.Color = topLine.Color;
            this.bottomLineNearestPoint.Direction   = NearestPointDirection.Vertical;
            this.bottomLineNearestPoint.DrawLine    = false;
            this.bottomLineNearestPoint.Series      = bottomLine;

            this.topLineAnnotation = new Annotation(this.tChart.Chart);

            this.topLineAnnotation.Position = AnnotationPositions.LeftTop;
            this.topLineAnnotation.Active   = false;

            this.bottomLineAnnotation = new Annotation(this.tChart.Chart);

            this.bottomLineAnnotation.Position = AnnotationPositions.RightBottom;
            this.bottomLineAnnotation.Active   = false;

            this.topLineDirectionComboBox.SelectedIndexChanged    += topLineDirectionComboBox_SelectedIndexChanged;
            this.bottomLineDirectionComboBox.SelectedIndexChanged += bottomLineDirectionComboBox_SelectedIndexChanged;
            this.tChart.MouseMove                                 += tChart_MouseMove;
            this.topLineNearestPoint.Change                       += topLineNearestPoint_Change;
            this.bottomLineNearestPoint.Change                    += bottomLineNearestPoint_Change;
        }

        #endregion

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

        #region 상단 라인 방향 콤보 박스 선택 인덱스 변경시 처리하기 - topLineDirectionComboBox_SelectedIndexChanged(sender, e)

        /// <summary>
        /// 상단 라인 방향 콤보 박스 선택 인덱스 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void topLineDirectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.topLineNearestPoint.Direction = (NearestPointDirection)this.topLineDirectionComboBox.SelectedIndex;
        }

        #endregion
        #region 하단 라인 방향 콤보 박스 선택 인덱스 변경시 처리하기 - bottomLineDirectionComboBox_SelectedIndexChanged(sender, e)

        /// <summary>
        /// 하단 라인 방향 콤보 박스 선택 인덱스 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void bottomLineDirectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.bottomLineNearestPoint.Direction = (NearestPointDirection)this.bottomLineDirectionComboBox.SelectedIndex;
        }

        #endregion
        #region TChart 마우스 이동시 처리하기 - tChart_MouseMove(sender, e)

        /// <summary>
        /// TChart 마우스 이동시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void tChart_MouseMove(object sender, MouseEventArgs e)
        {
            this.bottomLineNearestPoint.Active = e.Y > this.vertAxis.IStartPos && e.Y < this.vertAxis.IEndPos;

            this.topLineNearestPoint.Active = !this.bottomLineNearestPoint.Active;

            this.topLineAnnotation.Active = this.topLineNearestPoint.Active;
            this.bottomLineAnnotation.Active = this.bottomLineNearestPoint.Active;
        }

        #endregion
        #region 상단 라인 최근접 포인트 변경시 처리하기 - topLineNearestPoint_Change(sender, e)

        /// <summary>
        /// 상단 라인 최근접 포인트 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void topLineNearestPoint_Change(object sender, EventArgs e)
        {
            if(this.topLineNearestPoint.Point > -1)
            {
                this.topLineAnnotation.Text = $"상단 라인 Y 값 : {this.topLine.YValues[this.topLineNearestPoint.Point]}";
            }
        }

        #endregion
        #region 하단 라인 최근접 포인트 변경시 처리하기 - bottomLineNearestPoint_Change(sender, e)

        /// <summary>
        /// 하단 라인 최근접 포인트 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void bottomLineNearestPoint_Change(object sender, EventArgs e)
        {
            if(this.bottomLineNearestPoint.Point > -1)
            {
                this.bottomLineAnnotation.Text = $"하단 라인 Y 값 : {this.bottomLine.YValues[this.bottomLineNearestPoint.Point]}";
            }
        }

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

댓글을 달아 주세요