본문으로 바로가기

C# Chart Data 입력방법 및 X-Label 자동입력 결과

category 개발언어/C# 2017. 10. 1. 22:03

C# 에서 MSchart는 의외로 다양한 입력형태를 제공하고 있다.
많은 편리함을 제공한다

  1. series.Points.AddXY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    private void SplineChartExample()
    {
        this.chartControl.Series.Clear();
      
        this.chartControl.Titles.Add("Total Income");
      
        Series series = this.chartControl.Series.Add("Total Income");
        series.ChartType = SeriesChartType.Spline;
        series.Points.AddXY("September", 100);
        series.Points.AddXY("Obtober", 300);
        series.Points.AddXY("November", 800);
        series.Points.AddXY("December", 200);
        series.Points.AddXY("January", 600);
        series.Points.AddXY("February", 400);
    }

  2. series.Points.AddXY
    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
    public void GraphGenerate(Chart grph)
    {           DateTime[] dtx;
                double[][] DyArr = new double[2][];
                #region Data Generate
                ////////////////////////////////////////////////////////
                // Make Data
                Random r = new Random();
                DateTime start = DateTime.Parse(xtxt);
                int cnt = int.Parse(scnt);
                dtx = new DateTime[cnt];
                DyArr[0] = new double[cnt];
                DyArr[1] = new double[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    dtx[i] = start.AddMinutes(5*i);
                    DyArr[0][i] = Math.Sin(Math.PI * 0.1 * i)*r.Next(-1,100);
                    DyArr[1][i] = Math.Cos(Math.PI * 0.1 * i) * r.Next(-10, 50);
                }
                #endregion
                #region Draw Chart            
                for (int i = 0; i < cnt; i++)
                {
                    sers[0].Points.AddXY(dtx[i], DyArr[0][i]);
                    sers[1].Points.AddXY(dtx[i], DyArr[1][i]);
                }
               #endregion
    }

  3. series.Points.DataBindXY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    public void GraphGenerate(Chart grph)
    {           DateTime[] dtx;
                double[][] DyArr = new double[2][];
                #region Data Generate
                ////////////////////////////////////////////////////////
                // Make Data
                Random r = new Random();
                DateTime start = DateTime.Parse(xtxt);
                int cnt = int.Parse(scnt);
                dtx = new DateTime[cnt];
                DyArr[0] = new double[cnt];
                DyArr[1] = new double[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    dtx[i] = start.AddMinutes(5*i);
                    DyArr[0][i] = Math.Sin(Math.PI * 0.1 * i)*r.Next(-1,100);
                    DyArr[1][i] = Math.Cos(Math.PI * 0.1 * i) * r.Next(-10, 50);
                }
                #endregion
                #region Draw Chart           
               sers[0].Points.DataBindXY(dtx, DyArr[0]);
               sers[1].Points.DataBindXY(dtx, DyArr[1]);
               #endregion
    }