■ ColorLine 클래스를 사용해 SPC 품질 관리 시리즈의 상한 및 하한을 그리는 방법을 보여준다.
▶ 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 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Styles; using Steema.TeeChart.Tools; 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> /// 색상 라인 1 도구 /// </summary> private ColorLine colorLine1; /// <summary> /// 색상 라인 2 도구 /// </summary> private ColorLine colorLine2; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 라인 1 시리즈를 생성한다. this.line1 = new Line(); this.line1.Title = "Good"; this.line1.Color = Color.Blue; this.line1.Pointer.Visible = true; #endregion #region 라인 2 시리즈를 생성한다. this.line2 = new Line(); this.line2.Title = "Bad"; this.line2.Color = Color.Red; this.line2.Pointer.Visible = true; this.line2.VertAxis = VerticalAxis.Right; #endregion #region 색상 라인 1 도구를 생성한다. this.colorLine1 = new ColorLine(); this.colorLine1.Pen.Width = 2; this.colorLine1.Pen.Color = Color.Red; this.colorLine1.Axis = this.tChart.Axes.Right; #endregion #region 색상 라인 2 도구를 생성한다. this.colorLine2 = new ColorLine(); this.colorLine2.Pen.Width = 2; this.colorLine2.Pen.Color = Color.Blue; this.colorLine2.Axis = this.tChart.Axes.Right; #endregion #region 티차트를 설정한다. this.tChart.Axes.Left.Title.Caption = "Production (number of pieces)"; this.tChart.Axes.Left.Automatic = false; this.tChart.Axes.Left.AutomaticMaximum = false; this.tChart.Axes.Left.AutomaticMinimum = false; this.tChart.Axes.Left.Minimum = 0d; this.tChart.Axes.Left.Maximum = 1200d; this.tChart.Axes.Right.Title.Caption = "SPC (%)"; this.tChart.Axes.Right.Automatic = false; this.tChart.Axes.Right.AutomaticMaximum = false; this.tChart.Axes.Right.AutomaticMinimum = false; this.tChart.Axes.Right.Maximum = 10d; this.tChart.Axes.Right.Minimum = 0d; this.tChart.Axes.Bottom.Grid.Color = Color.FromArgb(130, 130, 130); this.tChart.Axes.Bottom.Grid.Visible = true; this.tChart.Tools.Add(this.colorLine1); this.tChart.Tools.Add(this.colorLine2); this.tChart.Series.Add(this.line1); this.tChart.Series.Add(this.line2); #endregion Random random = new Random(DateTime.Now.Millisecond); for(int i = 1 ; i < 19; i++) { this.line1.Add(800 + random.Next(200)); this.line2.Add(4 + random.Next(4 )); } CalculateLimits(this.line1, this.line2); this.upperLimitTextBox.Text = this.colorLine1.Value.ToString(); this.lowerLimitTextBox.Text = this.colorLine2.Value.ToString(); this.colorLine1.DragLine += colorLine1_DragLine; this.colorLine2.DragLine += colorLine2_DragLine; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 색상 라인 1 도구 라인 드래그시 처리하기 - colorLine1_DragLine(sender, e) /// <summary> /// 색상 라인 1 도구 라인 드래그시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void colorLine1_DragLine(object sender, EventArgs e) { this.upperLimitTextBox.Text = this.colorLine1.Value.ToString("#.00"); } #endregion #region 색상 라인 2 도구 라인 드래그시 처리하기 - colorLine2_DragLine(sender, e) /// <summary> /// 색상 라인 2 도구 라인 드래그시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void colorLine2_DragLine(object sender, EventArgs e) { this.lowerLimitTextBox.Text = this.colorLine2.Value.ToString("#.00"); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 제한 계산하기 - CalculateLimits(goodSeries, badSeries) /// <summary> /// 제한 계산하기 /// </summary> /// <param name="goodSeries">양품 시리즈</param> /// <param name="badSeries">불량 시리즈</param> private void CalculateLimits(Series goodSeries, Series badSeries) { double sum1 = 0d; double sum2 = 0d; double temporaryValue1; double temporaryValue2; double lcp; // Likelihood of Correct Prediction double lcn; // Likelihood of Correct Non-prediction double temporaryValue3; double percent; int n = 0; this.colorLine1.Value = 0.0; this.colorLine2.Value = 0.0; for(int i = 0; i < goodSeries.Count; i++) { percent = badSeries.YValues[i] * goodSeries.YValues[i] / 100.0; temporaryValue3 = goodSeries.YValues[i] + percent; if(temporaryValue3 > 0) { sum1 += percent / temporaryValue3; sum2 += temporaryValue3; n++; } } lcp = sum1 / n; lcn = sum2 / n; temporaryValue1 = (lcp * (1.0 - lcp)) / lcn; if(temporaryValue1 > 0) { temporaryValue2 = 3 * Math.Sqrt(temporaryValue1); this.colorLine1.Value = 100.0 * (lcp + temporaryValue2); this.colorLine2.Value = 100.0 * (lcp - temporaryValue2); } } #endregion } } |