Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a line chart with individual lines for each day of the week?
    primarykey
    data
    text
    <p>I have the following data in a database table, <strong>Columns</strong>: Date, Hour(from 1 to 24) and Temperature.</p> <p>I want to create a line chart that will show in the x-axis the hours from 1 to 24 and in the Y-axis the Temperatures.</p> <p>Now the tricky part is that I want to have different color lines for each date. So if the date is 2012-01-15 then I have a red line from 1 to 24 showing the variations in temperature. if the date is 2012-01-14 then a blue one also from 1 to 24.</p> <p>To be clear I want to have multiple dates in one chart.</p> <p>Here is some of code I have</p> <pre><code> SqlConnection conn2 = new SqlConnection(@"connectionString"); conn2.Open(); SqlCommand cmd2 = new SqlCommand(); cmd2.Connection = conn2; cmd2.CommandText = "SELECT * FROM observation WHERE day BETWEEN @fromDate AND @toDate ORDER BY day ASC, hour ASC "; cmd2.Parameters.AddWithValue("fromDate", dateTimePicker2.Value.Date); cmd2.Parameters.AddWithValue("toDate", dateTimePicker3.Value.Date); SqlDataReader reader = cmd2.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable("dateRange"); dt.Columns.Add("day"); dt.Columns.Add("hour"); dt.Columns.Add("temp"); DataRow dr = dt.NewRow(); int counter = 0; while (reader.Read()) { if (reader[1].ToString() != dt.TableName) { if (dt.Rows.Count != 0 &amp;&amp; dt.TableName != "dateRange") { dt.AcceptChanges(); ds.Tables.Add(dt); counter++; } dt = new DataTable(reader[1].ToString()); dt.Columns.Add("day"): dt.Columns.Add("hour"); dt.Columns.Add("temp"); } dr = dt.NewRow(); dr[0] = reader[2]; dr[1] = reader[3]; dt.Rows.Add(dr); } if (dt.Rows.Count != 0) { dt.AcceptChanges(); ds.Tables.Add(dt); } else { lblError.Visible = false; } for (int i = 0; i &lt; counter; i++) { chart1.Series[i].Name = i.ToString(); chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chart1.Series[i].BorderWidth = 5; if (i % 2 == 0) { chart1.Series[i].Color = Color.Red; } else { chart1.Series[i].Color = Color.Green; } chart1.DataSource = ds.Tables[i]; chart1.Series[i].XValueMember = "hour"; chart1.Series[i].YValueMembers = "temp"; } chart1.Legends[0].Alignment = StringAlignment.Center; chart1.Legends[0].Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; chart1.DataBind(); chart1.Visible = true; cmd2.Connection.Close(); </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload