0
編程的好日子,C#圖表 - 具有不同Y值的兩個圖表區域
我有一個問題。我創建了一個代碼,以chartarea1創建帶有datagridview作爲數據源的圖表。
Chart chart1 = new Chart();
chart1.Size = new System.Drawing.Size(1024, 768);
ChartArea chartArea1 = new ChartArea();
chartArea1.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisX.LabelStyle.Font = new Font("Consolas", 8);
chartArea1.AxisY.LabelStyle.Font = new Font("Consolas", 8);
chartArea1.AxisX.IntervalType = DateTimeIntervalType.Months;
chartArea1.AxisX.Interval = 1;
chart1.ChartAreas.Add(chartArea1);
chart1.Series.Add(new Series());
chart1.Series[0].XValueMember = dataGridView1.Columns[0].DataPropertyName;
chart1.Series[0].YValueMembers = dataGridView1.Columns[1].DataPropertyName;
chart1.DataSource = dataGridView1.DataSource;
chart1.Series[0].ChartType = SeriesChartType.Line;
現在我想創建一個相同的XValueMember但來自不同的DataGridView不同YValueMember,例如datagridview2 chart1內第二chartarea。可以做到嗎?
在此先感謝。
好了,我想這:
Chart chart1 = new Chart();
ChartArea chartArea1 = new ChartArea();
Series series1 = new Series();
chart1.DataSource = dataGridView1.DataSource;
chartArea1 = chart1.ChartAreas.Add("ca1");
chartArea1.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisX.LabelStyle.Font = new Font("Consolas", 8);
chartArea1.AxisY.LabelStyle.Font = new Font("Consolas", 8);
chartArea1.AxisX.IntervalType = DateTimeIntervalType.Months;
chartArea1.AxisX.Interval = 1;
series1 = chart1.Series.Add("s1");
series1.Points.DataBindXY(dataGridView1.Columns[0].DataPropertyName, dataGridView1.Columns[1].DataPropertyName);
series1.ChartType = SeriesChartType.Line;
chart1.SaveImage("chart.png", ChartImageFormat.Png);
現在收到此錯誤:
Y值不能綁定到字符串對象數據。 參數名稱:y值