C# 一个Form内 在chart控件中,当点击A按钮,显柱图,点击B按钮,显折线图
求高手们给予帮助
private void btnColumn_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=;database=;Uid=;Pwd=;";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from 电压寿命关系"; cmd.Connection = conn;
SqlDataReader read = cmd.ExecuteReader();
chart1.DataBindTable(read, "电压(V)");
conn.Close();
}
private void btnLine_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=;database=;Uid=;Pwd=;";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from 电压寿命关系"; cmd.Connection = conn;
SqlDataReader read = cmd.ExecuteReader();
chart1.DataBindTable(read, "电压(V)");
chart1.Series["寿命"].ChartType = SeriesChartType.Line;
}
我想当我点击某按钮时会显示不同图像,但报错已有一个相同名称的Serie存在,不知怎么办?
------解决方案--------------------
清空Serie试看。