1
你好,我試圖從SQL填充mschart,但即使系列具有不同的值,圖表是相同的。所以所有的系列都有相同的重疊線。Mschart從數據庫中獲得多個系列
sqlConnection.Open();
SqlCommand cmd = new SqlCommand(query, sqlConnection);
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 300;
rdr = cmd.ExecuteReader();
DataTable table = new DataTable();
// Add three columns to the table.
table.Columns.Add("Channel", typeof(String));
table.Columns.Add("Date", typeof(String));
table.Columns.Add("Value", typeof(Int32));
// Add data rows to the table.
while (rdr.Read())
{
table.Rows.Add(new object[] { rdr[0], rdr[1], rdr[2] });
}
chart1.DataSource = table;
//add series
for (int i = 0; i < table.Rows.Count; i++)
{
if (chart1.Series.Where(x => x.Name == table.Rows[i][0].ToString()).Count() > 0)
{
}
else
{
chart1.Series.Add(table.Rows[i][0].ToString());
}
}
//set x,y axis for each series
for (int i = 0; i < chart1.Series.Count; i++)
{
chart1.Series[i].XValueMember = "Date";
chart1.Series[i].YValueMembers = "Value";
chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
}
chart1.DataBind();
那麼所有的'DataSource'和X和Y值成員都一樣,顯示它們都會最終顯示同樣的事情! ! – V4Vendetta
好吧,我明白了謝謝 –