■ Axis 클래스의 Logarithmic/Labels 속성을 사용해 커스텀 로그 축을 만드는 방법을 보여준다.
▶ 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 |
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> /// 주 레이블 배열 카운트 /// </summary> private const int MAJOR_LABEL_ARRAY_COUNT = 4; /// <summary> /// 주 레이블 배열 /// </summary> private double[] majorLabelArray = new double[MAJOR_LABEL_ARRAY_COUNT]; /// <summary> /// 보조 틱 배열 /// </summary> private double[] minorTickArray = new double[2 * MAJOR_LABEL_ARRAY_COUNT - 2]; /// <summary> /// 라인 /// </summary> private Line line; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "Axis 클래스 : Logarithmic/Labels 속성을 사용해 커스텀 로그 축 만들기"; this.majorLabelArray[0] = 0.1; this.majorLabelArray[1] = 0.2; this.majorLabelArray[2] = 0.5; this.majorLabelArray[3] = 1.0; this.minorTickArray[0] = 0.12; this.minorTickArray[1] = 0.17; this.minorTickArray[2] = 0.30; this.minorTickArray[3] = 0.38; this.minorTickArray[4] = 0.55; this.minorTickArray[5] = 0.7; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.line = new Line(this.tChart.Chart); for(int i = 0; i < 100; i++) { this.line.Add(i, 2.0E-3 * (5 * i - 50) * (2 * i - 10) + 5.0); } this.logarithmicVerticalAxisCheckBox.CheckedChanged += logarithmicVerticalAxisCheckBox_CheckedChanged; this.customLogAxisIncrementCheckBox.CheckedChanged += customLogAxisIncrementCheckBox_CheckedChanged; this.tChart.BeforeDrawAxes += tChart_BeforeDrawAxes; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 로그 수직 축 체크 박스 체크 변경시 처리하기 - logarithmicVerticalAxisCheckBox_CheckedChanged(sender, e) /// <summary> /// 로그 수직 축 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void logarithmicVerticalAxisCheckBox_CheckedChanged(object sender, EventArgs e) { this.tChart.Axes.Left.Logarithmic = this.logarithmicVerticalAxisCheckBox.Checked; } #endregion #region 커스텀 로그 축 증분 체크 박스 체크 변경시 처리하기 - customLogAxisIncrementCheckBox_CheckedChanged(sender, e) /// <summary> /// 커스텀 로그 축 증분 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void customLogAxisIncrementCheckBox_CheckedChanged(object sender, EventArgs e) { this.tChart.Invalidate(); } #endregion #region TChart 축 그리기 전 처리하기 - tChart_BeforeDrawAxes(sender, graphics3D) /// <summary> /// TChart 축 그리기 전 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics3D">그래픽스 3D</param> private void tChart_BeforeDrawAxes(object sender, Graphics3D graphics3D) { if(this.logarithmicVerticalAxisCheckBox.Checked && this.customLogAxisIncrementCheckBox.Checked) { GenerateAxisLogarithmicLabels ( graphics3D, this.line.GetVertAxis, this.majorLabelArray, this.minorTickArray, this.line.GetHorizAxis.IStartPos, this.line.GetHorizAxis.IEndPos ); this.tChart.Invalidate(); } else { this.line.GetVertAxis.Labels.Items.Clear(); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 십진수 구하기 - GetDecade(value) /// <summary> /// 십진수 구하기 /// </summary> /// <param name="value">값</param> /// <returns>십진수</returns> private int GetDecade(double value) { double absoluteValue = Math.Abs(value); int decade = 0; if(absoluteValue >= 1.0) { while(absoluteValue >= 1.0) { absoluteValue /= 10.0; decade++; } } else { while(absoluteValue < 1.0) { absoluteValue *= 10.0; decade--; } } return decade; } #endregion #region 축 로그 레이블 생성하기 - GenerateAxisLogarithmicLabels(graphics3D, axis, majorLabelArray, minorTickArray, start, end) /// <summary> /// 축 로그 레이블 생성하기 /// </summary> /// <param name="graphics3D">그래픽스 3D</param> /// <param name="axis">축</param> /// <param name="majorLabelArray">주 레이블 배열</param> /// <param name="minorTickArray">보조 틱 배열</param> /// <param name="start">시작 보조 틱</param> /// <param name="end">종료 보조 틱</param> private void GenerateAxisLogarithmicLabels(Graphics3D graphics3D, Axis axis, double[] majorLabelArray, double[] minorTickArray, int start, int end) { axis.Labels.Items.Clear(); int minimumDecade = GetDecade(axis.Minimum); int maximumDecade = GetDecade(axis.Maximum); double currentValue; int tickPosition; start -= axis.MinorTicks.Length; end += axis.MinorTicks.Length; graphics3D.Pen.Style = axis.MinorGrid.Style; graphics3D.Pen.Color = axis.MinorGrid.Color; for(int i = minimumDecade ; i <= maximumDecade; i++) { for(int j = 0; j < majorLabelArray.Length; j++) { currentValue = majorLabelArray[j] * Math.Pow(10, i); if(currentValue >= axis.Minimum && currentValue <= axis.Maximum) { axis.Labels.Items.Add(currentValue); } } for(int k = 0; k < minorTickArray.Length; k++) { currentValue = minorTickArray[k] * Math.Pow(10, i); if(currentValue >= axis.Minimum && currentValue <= axis.Maximum) { tickPosition = axis.CalcPosValue(currentValue); if(axis.Horizontal) { graphics3D.Line(tickPosition, start, tickPosition, end); } else { graphics3D.Line(start, tickPosition, end, tickPosition); } } } } } #endregion } } |