protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("===============>Index changed"); BusinessLogic.Period period = BusinessLogic.Period.LAST_WEEK; switch (DropDownList1.SelectedIndex) { case (0): period = BusinessLogic.Period.TWELVE_HOUR; break; case (1): period = BusinessLogic.Period.TWENTYFOUR_HOUR; break; case (2): period = BusinessLogic.Period.LAST_WEEK; break; default: break; } this.LoadTemperatureChart(period); LoadingGif2.CssClass = "hidden"; }
protected void LoadTemperatureChart(BusinessLogic.Period period) { System.Diagnostics.Debug.WriteLine("-------------------In loadTemperatureChart"); List <Record <Double> > records = Manager.getTemperature(period); // set up some data List <DateTime> xvals = new List <DateTime>(); List <Double> yvals = new List <Double>(); foreach (Record <Double> record in records) { xvals.Add(DateTime.Parse(record.date)); yvals.Add(Math.Round(record.value, 1)); } Chart1.AntiAliasing = AntiAliasingStyles.Graphics; Chart1.BackColor = Color.Transparent; Chart1.ChartAreas["ChartArea1"].BackColor = Color.Transparent; switch (period) { case (BusinessLogic.Period.TWELVE_HOUR): Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "{0:HH:mm}"; break; case (BusinessLogic.Period.TWENTYFOUR_HOUR): Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "{0:HH:mm}"; break; case (BusinessLogic.Period.LAST_WEEK): Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "{0:dd/MM}"; break; default: break; } Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.LightGray; Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.LightGray; Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("Consolas", 10); Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.ForeColor = Color.White; Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.Font = new Font("Consolas", 10); Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor = Color.White; Chart1.ChartAreas["ChartArea1"].AxisY.Title = "C°"; Chart1.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = true; Chart1.ChartAreas["ChartArea1"].AxisY.MinorTickMark.Enabled = true; //chartArea.AxisX.Title = "Temperature chart of the last 24h " + ((DateTime)result.Rows[0]["time"]).ToString("dd/MMM"); //Chart1.ChartAreas.Add(chartArea); //var series = new Series(); //series.Name = "Series1"; Chart1.Series["Series1"].ChartType = SeriesChartType.Line; Chart1.Series["Series1"].XValueType = ChartValueType.DateTime; Chart1.Series["Series1"].Color = Color.Green; Chart1.Series["Series1"].BorderWidth = 5; //Chart1.Series["Series1"]["PointWidth"] = "0.6"; Chart1.Series["Series1"].IsValueShownAsLabel = true; //Chart1.Series.Add(series); // bind the datapoints Chart1.Series["Series1"].Points.DataBindXY(xvals, yvals); }