グラフ

private void btnSet_Click(object sender, EventArgs e)
        {

            var series1 = new Series("y = x*x");
            var series2 = new Series("y = 5*x+20");
            for (int x = 1; x < 10; x++)
            {
                series1.Points.AddXY(x, x * x);
                series2.Points.AddXY(x, 5 * x + 20);
            }
        
            
                series1.Color = Color.Red;
                series1.MarkerSize = 15;
                series1.MarkerStyle = MarkerStyle.Diamond;
                series1.IsValueShownAsLabel = true;
                series1.LabelForeColor = Color.Blue;
                series1.ChartType = SeriesChartType.Bar; // グラフ形状 
           
         
            
                series2.Color = Color.Blue;
                series2.MarkerColor = Color.Blue;
                series2.MarkerSize = 10;
                series2.MarkerStyle = MarkerStyle.Circle;
                series2.ChartType = SeriesChartType.Bar; // グラフ形状
           
           
                SampleChart.Series.Clear();
                SampleChart.Series.Add(series1);
                SampleChart.Series.Add(series2);
                SampleChart.ChartAreas[0].BackColor = Color.LightCyan;
           
           
                Axis ax = SampleChart.ChartAreas[0].AxisX;
                ax.MajorGrid.LineColor = Color.LightGray;
                Axis ay = SampleChart.ChartAreas[0].AxisY;
                ay.MajorGrid.LineColor = Color.LightGray;
           

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SampleChart.Series.Clear();
            SampleChart.Titles.Clear();

            var series = new Series("SampleGraph")
            {
                // 円グラフを指定
                ChartType = SeriesChartType.Pie,

                // 表題
                Label = "円グラフ",
            };

            var index = series.Points.AddXY(0, 10);
            series.Points[index].Name = "A001";
            series.Points[index].Label = "A001";

            index = series.Points.AddXY(0, 50);
            series.Points[index].Name = "A002";
            series.Points[index].Label = "A002";

            index = series.Points.AddXY(0, 40);
            series.Points[index].Name = "A003";
            series.Points[index].Label = "A003";

            // 円グラフの分割
            series.Points[index]["Exploded"] = "True";

            // 円グラフのタイトルを引き出す
            series.Points[index]["PieLabelStyle"] = "Outside";

            // 引き出し線の奥行き
            series.Points[index]["3DLabelLineSize"] = "10";

            SampleChart.ChartAreas[0].Area3DStyle.Enable3D = true;

            SampleChart.IsSoftShadows = true;
            SampleChart.Series.Add(series);
            SampleChart.Titles.Add("円グラフのサンプル");
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 1.Seriesの追加
            SampleChart.Series.Clear();
            SampleChart.Series.Add("sin");
            SampleChart.Series.Add("cos");

            // 2.グラフのタイプの設定
            SampleChart.Series["sin"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            SampleChart.Series["cos"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            // 3.座標の入力
            for (double theta = 0.0; theta <= 2 * Math.PI; theta += Math.PI / 360)
            {
                SampleChart.Series["sin"].Points.AddXY(theta, Math.Sin(theta));
                SampleChart.Series["cos"].Points.AddXY(theta, Math.Cos(theta));
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            string legend = "グラフ1";

            SampleChart.Series.Clear();  //グラフ初期化

            SampleChart.Series.Add(legend);  //グラフ追加
            //グラフの種類を指定(Columnは棒グラフ)
            SampleChart.Series[legend].ChartType = SeriesChartType.Column;
            SampleChart.Series[legend].LegendText = legend;  //凡例に表示するテキストを指定

            string[] xValues = new string[] { "A", "B", "C", "D", "E" };
            int[] yValues = new int[] { 10, 20, 30, 40, 50 };

            for (int i = 0; i < xValues.Length; i++)
            {
                //グラフに追加するデータクラスを生成
                DataPoint dp = new DataPoint();
                dp.SetValueXY(xValues[i], yValues[i]);  //XとYの値を設定
                dp.IsValueShownAsLabel = true;  //グラフに値を表示するように指定
                SampleChart.Series[legend].Points.Add(dp);   //グラフにデータ追加
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            chart1.ChartAreas.Clear();

            ChartArea a1 = new ChartArea("ChartArea1");
            a1.Area3DStyle.Enable3D = false;

            a1.BackColor = System.Drawing.Color.FromArgb(255, 255, 192);

            this.chart1.ChartAreas.Add(a1);


            chart1.Series.Clear();

            chart1.Series.Add("Series1");;
            chart1.Series["Series1"].IsVisibleInLegend = false;
            chart1.Series["Series1"].LegendText = "売上点数";

            chart1.Series["Series1"].ChartType = SeriesChartType.Column;


            chart1.Series["Series1"].BorderWidth = 3;




            chart1.Series["Series1"].Color = Color.Blue;

            chart1.Series["Series1"].YAxisType = AxisType.Secondary;

            //if (radioSyouhinBetu.Checked)
            //{
            chart1.Series.Add("Series2");
            chart1.Series["Series2"].IsVisibleInLegend = true;
            chart1.Series["Series2"].LegendText = "種別総売上";

            chart1.Series["Series2"].ChartType = SeriesChartType.Line;
            chart1.Series["Series2"].BorderWidth = 2;
            chart1.Series["Series2"].Color = Color.Red;



           
           chart1.Series["Series2"].MarkerSize = 3;
          
            chart1.Series["Series2"].MarkerStyle = MarkerStyle.Diamond;
           
          chart1.Series["Series2"].IsValueShownAsLabel = true;
         
            chart1.Series["Series2"].LabelForeColor = Color.Blue;
           
         



            //}

            for (int i = 1; i < 35; i++)
            {

                chart1.Series["Series1"].Points.AddXY(i, i + 5);

                chart1.Series["Series2"].Points.AddXY(i+10, i+35);

            }
        
        
        
        
        
        }

        private void button5_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 135; i++)
            {



                chart1.Series["Series1"].Points.AddXY(i, i + 5);

            }
        
        }

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です