System.Windows.Forms.DataVisualization.Charting.Chart

 //创建圖形式的Chart

            System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();

            //定义一个chart
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();

            //定义一个绘图区域
            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
            chartArea1.AxisY.LabelStyle.Format = "0%";
            //定义一个数据列
            chartArea1.Name = "ChartArea1";

            //其实没有必要,可以使用chart1。ChartAreas[0]就可以了
            chart1.ChartAreas.Add(chartArea1);

            //完成Chart和chartArea的关联
            //System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
            //legend1.Name = "图标";
            //chart1.Legends.Add(legend1);
            chart1.Name = "chart1";
            //series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;//定於為線性還是餅形
            //设置线性
            Random rd = new Random();
            double[] num = new double[20];

            //for (int i = 0; i < 20; i++)
            //{
            //    int valuey = rd.Next(1,1);
            //    DataPoint point = new DataPoint((i + 1), valuey);
            //    series1.Points.Add(point);
            //}
            DataPoint point = new DataPoint(( 1), 0.02);
            series1.Points.Add(point);
            //产生点的坐标
            //chart1.Titles[0].Text = "";

            series1.ChartArea = "ChartArea1";
            //chartArea1.AxisX.Title = "日期";

            //Title ttl = new Title("");
            //chart1.Titles.Add(ttl);
            //series1.ChartArea = "ChartArea1";
            //series1.BorderWidth = 1;
            //series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            //series1.Font = new System.Drawing.Font("Microsoft JhengHei",Convert.ToSingle( 10.0));
            //series1.IsValueShownAsLabel = false;
            //series1.IsVisibleInLegend = true;
            //series1.Legend = "Legend1";//
            //series1.LegendText = "2018";
            //series1.MarkerSize = 5;
            //series1.BorderWidth = 2;//
            //series1.MarkerColor = Color.Gray;
            //series1.Color = Color.Gray;//
            //series1.Name = "Series1";//
            //series1.ToolTip = "#VAL";
          




            chartArea1.AxisY.Title = "值";
            chartArea1.AxisX.Interval = 1;
           chartArea1.AxisY.Interval =0.0012;
            chartArea1.AxisY.Minimum = 0;
            //series1.Legend = "图标";
            series1.Name = "Series1";
            chart1.Text = "测试";
            //chart1.Size = new System.Drawing.Size(700, 500);
            chart1.Size = new System.Drawing.Size(1100, 600);
            //chart1.Location = new System.Drawing.Point(50,120);
            series1.Color = Color.Blue;
            chart1.Text = "ceshi";
            //chart1.Titles[0].Text = "fff";
            //chart1.Size = new System.Drawing.Size(1, 1);


            Legend Legend1 = new Legend();//初始化一个图例的实例

            Legend1.Alignment = System.Drawing.StringAlignment.Center;
            Legend1.BackImageAlignment = System.Windows.Forms.DataVisualization.Charting.ChartImageAlignmentStyle.Top;
            Legend1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            Legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom;
            //Legend1.Font = new System.Drawing.Font("Microsoft JhengHei", 10.0, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte));
            Legend1.IsTextAutoFit = true;
            Legend1.ItemColumnSpacing = 30;
            Legend1.MaximumAutoSize = Convert.ToSingle(30.0);
            Legend1.Name = "Legend1";
            Legend1.TitleFont = new System.Drawing.Font("Microsoft JhengHei",Convert.ToSingle( 10.0));
            chart1.Legends.Add(Legend1);



            chart1.Series.Add(series1);

            //这一句很重要,缺少的话绘图区域将显示空白
            //chart1.SizeChanged += new System.EventHandler(DoSizeChanged);
            //chart1.AllowDrop = true;
            chart1.BackColor = Color.FromArgb(243, 223, 193);

            //设置chart背景颜色
            chartArea1.BackColor = Color.FromArgb(243, 223, 193);

            //设置c绘图区域背景颜色
            series1.BorderWidth = 2;
            series1.IsValueShownAsLabel = true;

            //是否显示Y的值
        
            this.groupBox1.Controls.Add(chart1);
            this.panel1.Controls.Add(chart1);
            chart1.Visible = true;
            //this.label10.Visible = true;
            //this.label10.Text = "【" + tn.Name + "】图";
            chart1.Titles.Add("【wqqqd】图");
            //为Chart1添加标题
            chartArea1.AxisX.IsMarginVisible = true;

            //是否显示X轴两端的空白

            //2、在上述chart的基础上添加一条线

            Control[] controls = this.panel1.Controls.Find("chart1", true);

            //找到已经有的Chart1
            System.Windows.Forms.DataVisualization.Charting.Chart ch = (System.Windows.Forms.DataVisualization.Charting.Chart)controls[0];
            System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();

            //新定义一个数据项
            Random rd1 = new Random();
            //for (int i = 0; i < ch.Series[0].Points.Count; i++)
            //{
            //    int valuey = rd.Next(1, 1);
            //    DataPoint point = new DataPoint((i + 2), valuey);

            //    series2.Points.Add(point);
            //}
            DataPoint point1 = new DataPoint((1), 0.02);
            series2.Points.Add(point1);
            series2.Color = Color.FromArgb(rd1.Next(100, 255), rd1.Next(0, 150), rd1.Next(0, 255));
            series2.BorderWidth = 2;
            //series2.ChartType = ((System.Windows.Forms.DataVisualization.Charting.Chart)this.panel1.Controls[0]).Series[0].ChartType;
            series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;//定於為線性還是餅形
            //  series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;//设置图表的类型(饼状、线状等等)
            //series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;//设置图表的类型(饼状、线状等等)
            //定义线性和原有的线条形状一致
            series2.IsValueShownAsLabel = false;
            ch.Series.Add(series2);

            //添加数据列

            //3、减少一条曲线

            //Control[] controls1 = this.panel1.Controls.Find("chart1", true);
            //System.Windows.Forms.DataVisualization.Charting.Chart ch1 = (System.Windows.Forms.DataVisualization.Charting.Chart)controls[0];
            //if (ch1.Series.Count > 1)
            //{
            //    //MessageBox.Show(this, "去掉一条线!", "信息提示");
            //    int i = ch1.Series.Count - 1;
            //    while (i > 1)
            //    {
            //        if (ch1.Series[i].Points.Count > 0)
            //        {
            //            break;
            //        }
            //        i -= 1;
            //    }

            //    ch1.Series[i].Points.Clear();
            //    //this.toolStripStatusLabel2.Text = "减少对比曲线完成!";
            //}
            //else
            //{
            //    MessageBox.Show(this, "绘图区域至少要有一条线!", "信息提示");

            //}

 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

ManBOyyy

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值