WeatherOne : Forecasting Weather using WinForms Controls

ComponentOne Studio WinForms Edition provides a variety of controls that can be used in plenty of real-time applications. Consider the example of a Weather Forecasting application. Yes, the application of science and technology to predict the state of the atmosphere for a given location. The first thing that comes in mind as soon as we have considered the example is that it'll be all about Web technology and APIs. Let's take the challenge and measure the capabilities of the controls in WinForms Edition in this scenario. It'll be really exciting to see if the test fails or succeeds.

WeatherOne: Providing the User with Current and Forecast Weather Conditions

Will you need your snow boots tomorrow? Should you bring an umbrella? Accurate weather predictions are important for planning our day-to-day activities.

WeatherOne is a desktop application that provides the user with information on the current and forecast weather conditions. The application shows the current weather condition (e.g. Cloudy), temperature (in Celsius), wind speed and humidity through Gauges for WinForms. The application also provides seven-day forecast data of expected conditions and represents it through Chart for WinForms. The user can specify a location and, if internet connection is available, get the weather data for the specified location. In addition, it provides voice support and speaks out the current weather condition of the current location. You can also change the volume level, home location and auto refresh time intervals by simply accessing the settings bar.

Using an API and XML data to get the weather

WeatherOne application makes use of the API which returns XML data with weather information. However, you can use any other API for accomplishing the purpose.

The User Interface

In order to present the data in a meaningful and attractive way, we have made use of the Gauges and Charts from WinForms Edition of ComponentOne Studio. ComponentOne Studio Gauges for WinForms Gauge for WinForms offers various types of Linear and Radial gauges to provide an intuitive and attractive way to display information graphically. Gauges play an important role in Weather One; the leftmost Linear Gauge represents the current temperature of the location in Celsius with its filled bar and located pointer. The two Radial Gauges placed in the middle and right of the window shows the level of humidity in percentage and the speed of the wind in Knot respectively. For displaying the seven-day forecast in an eye-catching isometric view, Chart for WinForms has been used. It displays level of humidity in a XY Plot and both Temperature and Wind Speed in Bar Graphs.

Parsing the XML and Representing it in Controls

Since the weather information is available in XML data, the main task is to parse this data and represent it in the controls on the Form.

tempC1LinearGauge.Value = Math.Round(temp, 2);                      
humidityC1RadialGauge.Value = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("humidity").Attributes["value"].Value);  
windC1RadialGauge.Value = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("wind").FirstChild.Attributes["value"].Value) * 1.9438449;  

c1Chart1.DataSource = dt;  
c1Chart1.ChartGroups[1].ChartData[0].Y.DataField = "Temperature";  
c1Chart1.ChartGroups[0].ChartData[0].Y.DataField = "Humidity";  
c1Chart1.ChartGroups[1].ChartData[1].Y.DataField = "Wind_Speed";  


c1Chart1.ChartGroups[1].ChartData.SeriesList[0].DataLabel.Text = "{#YVAL}";  
c1Chart1.ChartGroups[1].ChartData.SeriesList[0].DataLabel.Compass = LabelCompassEnum.North;  
c1Chart1.ChartGroups[1].ChartData.SeriesList[0].DataLabel.Visible = true;  
c1Chart1.ChartGroups[0].ChartData.SeriesList[0].DataLabel.Text = "{#YVAL}";  
c1Chart1.ChartGroups[0].ChartData.SeriesList[0].DataLabel.Compass = LabelCompassEnum.North;  
c1Chart1.ChartGroups[0].ChartData.SeriesList[0].DataLabel.Visible = true;  
c1Chart1.ChartGroups[1].ChartData.SeriesList[1].DataLabel.Text = "{#YVAL}";  
c1Chart1.ChartGroups[1].ChartData.SeriesList[1].DataLabel.Compass = LabelCompassEnum.North;  
c1Chart1.ChartGroups[1].ChartData.SeriesList[1].DataLabel.Visible = true;  

So, the test succeeds with an eye-catching Weather Forecasting application. Thanks for reading! I hope it was useful. You can also share your comments below, if any.

Download Source Code


Read more about WinForms Edition >>


GrapeCity Developer Tools
comments powered by Disqus