private void DrawAllInOneGraph(double xmin, double xmax, double ymin, double ymax) { List <string> tableNames = new List <string>(); foreach (var item in GraphDaysCbx.ItemsSource) { tableNames.Add(item.ToString()); } List <DateTime> time = new List <DateTime>(); List <float> temperature = new List <float>(); List <float> humidity = new List <float>(); foreach (var name in tableNames) { var nameParts3 = name.Split('-'); List <DateTime> dateTimeList = new List <DateTime>(); List <float> temperatureList = new List <float>(); List <float> humidityList = new List <float>(); DatabaseOperations.GetTableData(_tableNamesDict[Convert.ToInt32(nameParts3[0])][Convert.ToInt32(nameParts3[1])], ref dateTimeList, ref temperatureList, ref humidityList); time.Add(dateTimeList.First()); temperature.Add(temperatureList.Average()); humidity.Add(humidityList.Average()); } int days = 0; days = (int)Math.Ceiling((time.Last() - time.First()).TotalDays); double xstep = xmax / days; double ystep_t = ymax / Math.Ceiling(temperature.Max() / 5); double ystep_h = ymax / 10; DrawX_Axis_AllInOne(xmin, ymax, days, xstep, time.First(), time.Last()); DrawY_Axis(xmin, xmax, ymax, temperature.Max(), ystep_t, ystep_h); double dayStep = xmax / days; double tempStep = ymax / (Math.Ceiling(temperature.Max() / 5) * 5); double humStep = ymax / 100; DrawGraphLine(Brushes.Red, time, temperature, 0, 0, 0, 0, tempStep, ymax, false, time.First(), dayStep); DrawGraphLine(Brushes.Blue, time, humidity, 0, 0, 0, 0, humStep, ymax, false, time.First(), dayStep); //DrawGraphLine(Brushes.Blue, dateTimeList, humidityList, hours.Min(), hourStep, minuteStep, secondStep, humStep, ymax); DrawGraphLineColorNotations(ymax); MaxTempHumLbl.Content = Math.Round(temperature.Max(), 1) + "°C; " + Math.Round(humidity.Max(), 1) + "%"; MinTempHumLbl.Content = Math.Round(temperature.Min(), 1) + "°C; " + Math.Round(humidity.Min(), 1) + "%"; }
private void DrawDayGraph(double xmin, double xmax, double ymin, double ymax, string day) { List <DateTime> dateTimeList = new List <DateTime>(); List <float> temperatureList = new List <float>(); List <float> humidityList = new List <float>(); DatabaseOperations.GetTableData(day, ref dateTimeList, ref temperatureList, ref humidityList); List <int> hours = new List <int>(); foreach (var time in dateTimeList) { hours.Add(time.Hour); } int hourDifference = hours.Max() - hours.Min(); if (hourDifference != 24) { hourDifference += 1; } double xstep = xmax / hourDifference; double ystep_t = ymax / Math.Ceiling(temperatureList.Max() / 5); double ystep_h = ymax / 10; DrawX_Axis_Day(xmin, ymax, hourDifference, xstep, hours.Min()); DrawY_Axis(xmin, xmax, ymax, temperatureList.Max(), ystep_t, ystep_h); //calculate step size double hourStep = xmax / hourDifference; double minuteStep = xmax / (hourDifference * 60); double secondStep = xmax / (hourDifference * 3600); double tempStep = ymax / (Math.Ceiling(temperatureList.Max() / 5) * 5); double humStep = ymax / 100; DrawGraphLine(Brushes.Red, dateTimeList, temperatureList, hours.Min(), hourStep, minuteStep, secondStep, tempStep, ymax, true, DateTime.Now, 0); DrawGraphLine(Brushes.Blue, dateTimeList, humidityList, hours.Min(), hourStep, minuteStep, secondStep, humStep, ymax, true, DateTime.Now, 0); DrawGraphLineColorNotations(ymax); MaxTempHumLbl.Content = Math.Round(temperatureList.Max(), 1) + "°C; " + Math.Round(humidityList.Max(), 1) + "%"; MinTempHumLbl.Content = Math.Round(temperatureList.Min(), 1) + "°C; " + Math.Round(humidityList.Min(), 1) + "%"; }