Reputation: 451
I've encountered an error while creating line charts with the Winform chart control. (I'm using VS2013)
I'm plotting a line chart and it produces the strange visual effect of a single solid line connecting the first and last points in addition to the correct points.
I don't want the straight line. When I plot this in Excel, I get the correct graph so I know the data series is good.
I've tinkered with many of the series settings but cannot get the straight line to go away. Can this be fixed?
My code that produces the series is below. Thank you for helping.
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
foreach (var series in chart1.Series)
{
series.Points.Clear();
}
string chartValues = "SELECT statDay, itemCount, [60DayMAVG] FROM tbl_MAVG_dev WHERE streamID = " + numericUpDown1.Value;
SqlConnection getStreamData = new SqlConnection("Data Source=SQLSERVER;Initial Catalog=MyOwnSQLBox;Integrated Security=True");
SqlCommand getValuesCMD = new SqlCommand(chartValues, getStreamData);
try
{
getStreamData.Open();
SqlDataReader getValuesReader = getValuesCMD.ExecuteReader();
while (getValuesReader.Read())
{
//chart1.Series["itemCount"].Points.AddXY(Convert.ToDateTime(getValuesReader.GetDateTime(0)), Convert.ToInt32(getValuesReader.GetInt64(1)));
chart1.Series["mavg"].Points.AddXY(Convert.ToDateTime(getValuesReader.GetDateTime(0)), Convert.ToInt32(getValuesReader.GetDouble(2)));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Upvotes: 2
Views: 2340
Reputation: 1610
One of your end points is out of date order and/or you have a duplicate of one of the end points.
Upvotes: 2