public ForecastChart(RootObjectForecast root)
        {
            InitializeComponent();
            Title = "Forecast Chart";

            List <Entry> entries = new List <Entry>();

            foreach (var element in root.list)
            {
                float temperature = (float)element.main.temp;

                var entry = new Entry(temperature)
                {
                    Color      = SKColor.Parse("#FF1493"),
                    Label      = element.Date,
                    ValueLabel = temperature.ToString() + " ºC"
                };
                entries.Add(entry);
            }

            ForecastChartView.Chart = new LineChart
            {
                Entries       = entries,
                LineMode      = LineMode.Straight,
                LabelTextSize = 30f,
            };
        }
Exemple #2
0
        public async Task <RootObjectForecast> GetForecast(string cityName)
        {
            string              apiKey = "6418ce6c8e4fd8f4c2c5c0bfd7f52a17";
            HttpClient          client = new HttpClient();
            HttpResponseMessage response;

            try
            {
                response = await client.GetAsync($"http://api.openweathermap.org/data/2.5/forecast?q={cityName}&units=metric&appid={apiKey}");

                if (response.StatusCode == (HttpStatusCode)404)
                {
                    throw new ExceptionModel();
                }

                HttpContent content = response.Content;

                string data = await content.ReadAsStringAsync();

                RootObjectForecast weather = JsonConvert.DeserializeObject <RootObjectForecast>(data);

                return(weather);
            }
            catch (ExceptionModel exception)
            {
                Response.StatusCode = 404;
                return(null);
            }
        }
 private void BindForecastInformation(RootObjectForecast root)
 {
     root.list.RemoveRange(8, root.list.Count - 8);
     WeatherForecastList.ItemsSource = root.list;
     forecastRoot = root;
 }