在C#中使用MsChart的错误 [英] error on using MsChart in C#

查看:97
本文介绍了在C#中使用MsChart的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MsChart在表单上绘制图表.
我使用了以下代码:

Hi,I''m trying to draw a chart on my form by using MsChart.
I have used the following codes:

Legend Legend1;
          // Create a Chart
         Chart chart1 = new Chart();

          // Create Chart Area
          ChartArea chartArea1 = new ChartArea();

          // Add Chart Area to the Chart
          chart1.ChartAreas.Add(chartArea1);

          // Create a data series
          Series series1 = new Series("series1");
          Series series2 = new Series("series2");
          //********************************زوم کردن
          // Enable range selection and zooming end user interface
          chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
          chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
          chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
          chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
          chartArea1.AxisX.ScaleView.Size = 200;
          //*******************************************************
          //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++           // show the chart in 3D
          chart1.ChartAreas[0].Area3DStyle.Enable3D = true;

          // set the Rotation value
          chart1.ChartAreas[0].Area3DStyle.Rotation = 10;

          // set the Inclination value
          chart1.ChartAreas[0].Area3DStyle.Inclination = 40;

          // set the wall width for the axis
          chart1.ChartAreas[0].Area3DStyle.WallWidth = 7;




          // Add data points to the first series

          //  series1.BackGradientStyle=GradientStyle.TopBottom ;
          //هاشور زدن
          //  series1.BackHatchStyle = ChartHatchStyle.HorizontalBrick;
          //عکس پس زمینه
          //    series1.BackImage = @"F:\Picture\us337misdildf391klt.jpg";
          //عکس پس زمینه کجا باشد
          //series1.BackImageAlignment = ChartImageAlignmentStyle.BottomLeft;
          series1.BackSecondaryColor = Color.PowderBlue;
          series1.BackSecondaryColor = Color.Red;
          series1.BackImageTransparentColor = Color.Red;
          // بعضی از انواع باید یک جور باشند مثل رادار
          series1.ChartType = SeriesChartType.Pyramid;
          series2.ChartType = SeriesChartType.Pyramid;





          //    series1.ChartArea = "hasan";
          series1.Points.Add(34);
          series1.Points.Add(24);
          series1.Points.Add(32);
          series1.Points.Add(28);
          series1.Points.Add(44);

          // Add data points to the second series
          series2.Points.Add(14);
          series2.Points.Add(44);
          series2.Points.Add(24);
          series2.Points.Add(32);
          series2.Points.Add(28);

          // Add series to the chart
          chart1.Series.Add(series1);
          chart1.Series.Add(series2);

          // Set chart control location
          chart1.Location = new System.Drawing.Point(16, 48);

          // Set Chart control size
          chart1.Size = new System.Drawing.Size(360, 260);

          // Add chart control to the form
          this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chart1 });
          //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          //&&&&&&&&&&&&&&&&&&&&&&&&&&&اضافه نمودن جزیات
          Legend1 = new Legend("legend1");
          this.chart1.Legends.Add(Legend1);
          chart1.Series["series1"].Palette = ChartColorPalette.BrightPastel;
          chart1.Series["series1"].IsVisibleInLegend = false;
          chart1.ApplyPaletteColors();
          foreach (DataPoint dp in chart1.Series["series1"].Points)
          {
              chart1.Legends["legend1"].CustomItems.Add(dp.Color, dp.AxisLabel);
          }



但在"



but it gives me error at the line"

this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chart1 });


"和

"this.chart1.Legends.Add(Legend1);"


推荐答案

我自己找到了答案.我改变了这一行:
I found the answer myself .I changed the line:
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chart1 });


到线:


to the line:

this.Controls.AddRange(new System.Windows.Forms.Control[] { chart1});


和线


and the line

this.chart1.Legends.Add(Legend1);


到线


to the line

chart1.Legends.Add(Legend1);


这篇关于在C#中使用MsChart的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆