■ TChart 클래스의 Scroll 이벤트를 사용해 복수 축을 스크롤하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 고속 라인 1 /// </summary> private FastLine fastLine1; /// <summary> /// 고속 라인 2 /// </summary> private FastLine fastLine2; /// <summary> /// 캔들 /// </summary> private Candle candle; /// <summary> /// 볼륨 /// </summary> private Volume volume; /// <summary> /// 녹색 축 /// </summary> private Axis greenAxis; /// <summary> /// 청색 축 /// </summary> private Axis blueAxis; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "TChart 클래스 : Scroll 이벤트를 사용해 복수 축 스크롤하기"; this.redCheckBox.Checked = true; this.greenCheckBox.Checked = true; this.blueCheckBox.Checked = true; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Axes.Bottom.Grid.Visible = true; this.tChart.Legend.Visible = false; Axis redAxis = this.tChart.Axes.Left; redAxis.StartPosition = 0; redAxis.EndPosition = 32; redAxis.AxisPen.Color = Color.Red; this.greenAxis = new Axis(); this.greenAxis.StartPosition = 34; this.greenAxis.EndPosition = 65; this.greenAxis.AxisPen.Color = Color.Green; this.tChart.Axes.Custom.Add(greenAxis); this.blueAxis = new Axis(); this.blueAxis.StartPosition = 67; this.blueAxis.EndPosition = 100; this.blueAxis.AxisPen.Color = Color.Blue; this.tChart.Axes.Custom.Add(blueAxis); this.fastLine1 = new FastLine(this.tChart.Chart); this.fastLine1.VertAxis = VerticalAxis.Left; this.fastLine2 = new FastLine(this.tChart.Chart); this.fastLine2.VertAxis = VerticalAxis.Left; this.candle = new Candle(this.tChart.Chart); this.candle.CustomVertAxis = greenAxis; this.volume = new Volume(this.tChart.Chart); this.volume.CustomVertAxis = blueAxis; foreach(Series series in this.tChart.Series) { series.FillSampleValues(100); } this.tChart.Scroll += tChart_Scroll; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region TChart 스크롤시 처리하기 - tChart_Scroll(sender, e) /// <summary> /// TChart 스크롤시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_Scroll(object sender, EventArgs e) { double redAxisMinimum; double redAxisMaximum; if(!this.redCheckBox.Checked) { redAxisMinimum = Math.Min(this.fastLine1.YValues.Minimum, this.fastLine2.YValues.Minimum); redAxisMaximum = Math.Max(this.fastLine1.YValues.Maximum, this.fastLine2.YValues.Maximum); this.tChart.Axes.Left.SetMinMax(redAxisMinimum, redAxisMaximum); } if(!this.blueCheckBox.Checked) { this.blueAxis.SetMinMax(this.volume.YValues.Minimum, this.volume.YValues.Maximum); } if(!this.greenCheckBox.Checked) { this.greenAxis.SetMinMax(this.candle.YValues.Minimum, this.candle.YValues.Maximum); } } #endregion } } |