■ 복수 축 사용시 불투명 영역을 처리하는 방법을 보여준다.
▶ 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
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 Line line1; /// <summary> /// 라인 2 /// </summary> private Line line2; /// <summary> /// 라인 3 /// </summary> private Line line3; /// <summary> /// 라인 4 /// </summary> private Line line4; /// <summary> /// Y 마우스 DOWN /// </summary> private int yMouseDown; /// <summary> /// Y 마우스 UP /// </summary> private int yMouseUp; /// <summary> /// 확대 여부 /// </summary> private bool zoomed = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "복수 축 사용시 불투명 영역 처리하기"; this.opaqueZoneCheckBox.Checked = true; this.hScrollBar.Value = 50; this.tChart.Panel.Pen = new ChartPen(Color.Black); Axis axis1 = new Axis(); axis1.StartPosition = 25; axis1.EndPosition = 50; axis1.Horizontal = false; axis1.OtherSide = false; this.tChart.Axes.Custom.Add(axis1); Axis axis2 = new Axis(); axis2.StartPosition = 50; axis2.EndPosition = 75; axis2.Horizontal = false; axis2.OtherSide = false; this.tChart.Axes.Custom.Add(axis2); Axis axis3 = new Axis(); axis3.StartPosition = 75; axis3.Horizontal = false; axis3.OtherSide = false; this.tChart.Axes.Custom.Add(axis3); this.line1 = new Line(this.tChart.Chart); this.line1.VertAxis = VerticalAxis.Left; this.line1.FillSampleValues(20); this.line2 = new Line(this.tChart.Chart); this.line2.CustomVertAxis = axis1; this.line2.FillSampleValues(20); this.line3 = new Line(this.tChart.Chart); this.line3.CustomVertAxis = axis2; this.line3.FillSampleValues(20); this.line4 = new Line(this.tChart.Chart); this.line4.CustomVertAxis = axis3; this.line4.FillSampleValues(20); this.opaqueZoneCheckBox.CheckedChanged += opaqueZoneCheckBox_CheckedChanged; this.hScrollBar.Scroll += hScrollBar_Scroll; this.tChart.Zoomed += tChart_Zoomed; this.tChart.UndoneZoom += tChart_UndoneZoom; this.tChart.MouseDown += tChart_MouseDown; this.tChart.MouseUp += tChart_MouseUp; this.line1.BeforeDrawValues += line_BeforeDrawValues; this.line1.AfterDrawValues += line_AfterDrawValues; this.line2.BeforeDrawValues += line_BeforeDrawValues; this.line2.AfterDrawValues += line_AfterDrawValues; this.line3.BeforeDrawValues += line_BeforeDrawValues; this.line3.AfterDrawValues += line_AfterDrawValues; this.line4.BeforeDrawValues += line_BeforeDrawValues; this.line4.AfterDrawValues += line_AfterDrawValues; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 불투명 영역 체크 박스 체크 변경시 처리하기 - opaqueZoneCheckBox_CheckedChanged(sender, e) /// <summary> /// 불투명 영역 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void opaqueZoneCheckBox_CheckedChanged(object sender, EventArgs e) { this.tChart.Invalidate(); } #endregion #region 수평 스크롤바 스크롤시 처리하기 - hScrollBar_Scroll(sender, e) /// <summary> /// 수평 스크롤바 스크롤시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void hScrollBar_Scroll(object sender, ScrollEventArgs e) { ProcessScroll(this.line1); ProcessScroll(this.line2); ProcessScroll(this.line3); ProcessScroll(this.line4); } #endregion #region TChart 마우스 DOWN 처리하기 - tChart_MouseDown(sender, e) /// <summary> /// TChart 마우스 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_MouseDown(object sender, MouseEventArgs e) { this.yMouseDown = e.Y; } #endregion #region TChart 마우스 UP 처리하기 - tChart_MouseUp(sender, e) /// <summary> /// TChart 마우스 UP 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_MouseUp(object sender, MouseEventArgs e) { if(this.zoomed) { this.yMouseUp = e.Y; double maximumValue = this.line2.YScreenToValue(this.yMouseDown); double minimumValue = this.line2.YScreenToValue(this.yMouseUp ); this.line2.CustomVertAxis.SetMinMax(minimumValue, maximumValue); maximumValue = this.line3.YScreenToValue(this.yMouseDown); minimumValue = this.line3.YScreenToValue(this.yMouseUp ); this.line3.CustomVertAxis.SetMinMax(minimumValue, maximumValue); maximumValue = this.line4.YScreenToValue(this.yMouseDown); minimumValue = this.line4.YScreenToValue(this.yMouseUp ); this.line4.CustomVertAxis.SetMinMax(minimumValue, maximumValue); } } #endregion #region TChart 확대시 처리하기 - tChart_Zoomed(sender, e) /// <summary> /// TChart 확대시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_Zoomed(object sender, EventArgs e) { this.zoomed = true; } #endregion #region TChart 확대 취소시 처리하기 - tChart_UndoneZoom(sender, e) /// <summary> /// TChart 확대 취소시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_UndoneZoom(object sender, EventArgs e) { this.zoomed = false; this.line2.CustomVertAxis.Automatic = true; this.line3.CustomVertAxis.Automatic = true; this.line4.CustomVertAxis.Automatic = true; } #endregion #region 라인 값 그리기 전 처리하기 - line_BeforeDrawValues(sender, graphics3D) /// <summary> /// 라인 값 그리기 전 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics3D">그래픽스 3D</param> private void line_BeforeDrawValues(object sender, Graphics3D graphics3D) { if(this.opaqueZoneCheckBox.Checked) { Line line = sender as Line; int left = line.GetHorizAxis.IStartPos; int right = line.GetHorizAxis.IEndPos; int top = line.GetVertAxis.IStartPos; int bottom = line.GetVertAxis.IEndPos; this.tChart.Graphics3D.ClipRectangle(left, top, right, bottom); } } #endregion #region 라인 값 그리기 후 처리하기 - line_AfterDrawValues(sender, graphics3D) /// <summary> /// 라인 값 그리기 후 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics3D">그래픽스 3D</param> private void line_AfterDrawValues(object sender, Graphics3D graphics3D) { if(this.opaqueZoneCheckBox.Checked) { this.tChart.Graphics3D.ClearClipRegions(); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 스크롤 처리하기 - ProcessScroll(line) /// <summary> /// 스크롤 처리하기 /// </summary> /// <param name="line">라인</param> private void ProcessScroll(Line line) { double value = 0.01 * ((int)this.hScrollBar.Value - 50) * (line.YValues.Maximum - line.YValues.Minimum); line.GetVertAxis.SetMinMax(line.YValues.Maximum + value, line.YValues.Minimum + value); } #endregion } } |