private void cbLaw_Change(object sender, EventArgs e) { LawX.Clear(); LawY.Clear(); if (cbLaw.SelectedItem.ToString() != null) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(lawPath); foreach (System.IO.FileInfo file in di.GetFiles()) { if (cbLaw.SelectedItem.ToString().Equals(file.Name.Replace(".txt", ""))) { string[] textValue = System.IO.File.ReadAllLines(file.FullName); for (var i = 0; i < textValue.Length; i++) { string[] vs = textValue[i].Split(' '); LawX.Add((double)(new decimal(Convert.ToDouble(vs[0])))); LawY.Add((double)(new decimal(Convert.ToDouble(vs[1])))); #region SET GraphDetail's LawX & LawY graphDetail.LawX = LawX.ToList(); graphDetail.LawY = LawY.ToList(); #endregion } } } } }
public void DrawGraph() { if (LawX.Count + LawY.Count > 0) { List <PointF> Point_temp = SortPointPoly(this.LawX, this.LawY); this.LawX.Clear(); this.LawY.Clear(); string temp = ""; for (int i = 0; i < Point_temp.Count; i++) { this.LawX.Add(Convert.ToDouble((double)(new decimal(Point_temp[i].X)))); this.LawY.Add(Convert.ToDouble((double)(new decimal(Point_temp[i].Y)))); temp += $"({this.LawX[i]}, {this.LawY[i]})\r\n"; } ////////////////////////////////////////////////////////////////// chtResult.Series.Clear(); chtResult.ChartAreas.Clear(); ChartArea GraphArea = chtResult.ChartAreas.Add("Result"); Series Lines = chtResult.Series.Add("Lines"); //새로운 series 생성 Lines.IsVisibleInLegend = false; Lines.ChartType = SeriesChartType.Line; Lines.BorderWidth = 2; for (int i = 0; i < LawX.Count; i++) { Lines.Points.AddXY(LawX[i], LawY[i]); if (i == LawX.Count - 1) { Lines.Points.AddXY(LawX[0], LawY[0]); } } Series pPoint = chtResult.Series.Add("Point"); pPoint.ChartType = SeriesChartType.Point; pPoint.IsVisibleInLegend = false; pPoint.Color = Color.Red; pPoint.Points.AddXY((double)PointResult.X, (double)PointResult.Y); double Xinterval = CustomTruncate(LawX.Max() - LawX.Min()); double Yinterval = CustomTruncate(LawY.Max() - LawY.Min()); Xinterval = 0.01; Yinterval = 0.01; GraphArea.AxisX.Interval = Xinterval; // 수정 하자 GraphArea.AxisX.Minimum = CustomTruncate(LawX.Min() - Xinterval); GraphArea.AxisX.Maximum = CustomTruncate(LawX.Max() + Xinterval); GraphArea.AxisY.Interval = Yinterval; GraphArea.AxisY.Minimum = CustomTruncate(LawY.Min() - Yinterval); GraphArea.AxisY.Maximum = CustomTruncate(LawY.Max() + Yinterval); if (PointResult.X < GraphArea.AxisX.Minimum) { GraphArea.AxisX.Minimum = ((double)(new decimal(PointResult.X))) - Xinterval; GraphArea.AxisX.Minimum = CustomTruncate(GraphArea.AxisX.Minimum); } if (PointResult.X > GraphArea.AxisX.Maximum) { GraphArea.AxisX.Maximum = ((double)(new decimal(PointResult.X))) + Xinterval; GraphArea.AxisX.Maximum = CustomTruncate(GraphArea.AxisX.Maximum); } if (PointResult.Y < GraphArea.AxisY.Minimum) { GraphArea.AxisY.Minimum = ((double)(new decimal(PointResult.Y))) - Yinterval; GraphArea.AxisY.Minimum = CustomTruncate(GraphArea.AxisY.Minimum); } if (PointResult.Y > GraphArea.AxisY.Maximum) { GraphArea.AxisY.Maximum = ((double)(new decimal(PointResult.Y))) + Yinterval; GraphArea.AxisY.Maximum = CustomTruncate(GraphArea.AxisY.Maximum); } #region Added at 2021.02.20 (1) GraphArea.AxisX.MajorGrid.Interval = GraphArea.AxisX.Maximum - GraphArea.AxisX.Minimum; GraphArea.AxisX.LabelAutoFitMaxFontSize = 7; //set gbGraph's BackGround Color WHITE!! #endregion } }