找不到C#图表系列

本文关键字:系列 找不到 | 更新日期: 2023-09-27 18:27:10

嘿,我对图表系列有问题

这是表格。签名者:

System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(7, 17);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
series1.IsXValueIndexed = true;
series1.Legend = "Legend1";
series1.MarkerColor = System.Drawing.Color.Red;
series1.MarkerSize = 6;
series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
series1.Name = "SeriesBatchPoint";
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(1141, 323);
this.chart1.TabIndex = 3;
this.chart1.Text = "chart1";

在表格中,我会指出

chart1.Series["SeriesBatchPoint"].Points.AddXY(BatchCount, aTempWeightMesure);

我得到这个错误:

ArgumentException未处理

其他信息:在"ChartAreaCollection"中找不到名为"SeriesBatchPoint"的图表元素。

我做错了什么?

找不到C#图表系列

试试这个:

var series1 = chart1.Series.Add("SeriesBatchPoint");
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
// etc