System.Windows.Forms.DataVisualization.Charting.Chart

本文深入剖析了System.Windows.Forms.DataVisualization.Charting.Chart组件,讲解如何在Windows Forms应用中创建和定制数据图表,包括设置数据源、自定义样式、交互功能等关键特性。
 //创建圖形式的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, "绘图区域至少要有一条线!", "信息提示");

            //}

 

第一步:您从我们网站下载下来文件之后,先将其解压(一般都是zip压缩包)。 第二步:然后根据您系统的情况选择X86/X64,X86为32位电脑,X64为64位电脑。 如果您不知道是X86还是X64,您可以点此链接检测。 第三步:根据软件情况选择文件版本。此步骤比较复杂,如果是Windows的dll文件,     版本号以5.0开头的或含有 nt 一般是windows2000的文件。     版本号以5.1开头的或含有 xp、xpsp1、xpsp2、xpsp3 信息的一般是windowsXP的文件。     版本号以6.0开头的或含有 longhorn、vista 信息的一般是windowsVista的文件。     版本号以6.1开头的或含有 win7 信息的一般是windows7的文件。     版本号以6.2开头的或含有 win8 信息的一般是windows8的文件。     版本号以6.3开头的或含有 win8.1 信息的一般是windows8.1的文件。     版本号以10.0开头的或含有 win10 信息的一般是windows10的文件。     如果不是windows的dll文件,则需要灵活查看版本号、描述、网友提供的信息、以及相关dll的版本号去判断。 如果实在无法判断,则把每个版本的dll文件拷贝到对应目录(可以在我们网站上文件详细页面查看到)或 C:\Windows\System (Windows 95/98/Me), C:\WINNT\System32 (Windows NT/2000), C:\Windows\System32 (Windows XP,Vista,7) , 去尝试。 至此如果问题依旧,您可能需要使用regsvr32,方法如下: 1.单击开始,选择运行 2.输入 regsvr32 文件名.dll 并按下确认 之后会弹出注册成功信息。 另外,您还可以使用我们的修复工具进行修复。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值