Esempio n. 1
0
        private List <WeatherInfo> get5DayWeather()
        {
            string locale                  = txt_cityname.Text;
            EindopdrachtEntities db        = new EindopdrachtEntities();
            DateTime             beginDate = DateTime.Today.AddDays(-5);
            DateTime             endDate   = DateTime.Today;

            WeatherInfo[] histData = db.WeatherInfoes.Where(record => record.Timestamp >= beginDate && record.Timestamp <= endDate).ToArray();
            return(histData.Where(data => data.Locale == locale).ToList());
        }
Esempio n. 2
0
        private void drawGraph()
        {
            EindopdrachtEntities db = new EindopdrachtEntities();

            List <WeatherInfo> dataForGraph = get5DayWeather();
            List <DateTime>    dates        = dataForGraph.Select(n => n.Timestamp.Value.Date).Distinct().ToList();
            List <double>      temps        = new List <double>();

            if (radio_celsius.Checked)
            {
                foreach (var date in dates)
                {
                    temps.Add(dataForGraph.Where(all => all.Timestamp.Value.Date == date).Average(avg => double.Parse(avg.Temperature)));
                }
            }
            else
            {
                foreach (var date in dates)
                {
                    double temp = dataForGraph.Where(all => all.Timestamp.Value.Date == date).Average(avg => double.Parse(avg.Temperature));
                    temps.Add(((9.0 / 5.0) * temp + 32));
                }
            }

            chart1.Series.Clear();
            //Create a new Chart and add data
            var series = new Series("Gemiddelde temperatuur");

            series.ChartType = SeriesChartType.Line;
            series.Points.DataBindXY(dates.ToArray(), temps.ToArray());
            //Kies het correcte label voor de Y Axis
            if (radio_celsius.Checked)
            {
                chart1.ChartAreas[0].AxisY.LabelStyle.Format = "{#,##} \u00B0" + "C";
            }
            else
            {
                chart1.ChartAreas[0].AxisY.LabelStyle.Format = "{#,##} \u00B0" + "F";
            }

            chart1.Series.Add(series);
            chart1.Series[0].IsVisibleInLegend         = false;
            chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
            chart1.ChartAreas[0].RecalculateAxesScale();

            //kijkt of er een stad is ingevoert
            if (txt_cityname.Text != "")
            {
                lbl_graphCityName.Text = txt_cityname.Text;
            }
            else if (txt_cityname.Text == "")
            {
                lbl_graphCityName.Text = "Emmen";
            }
        }