Click here to Skip to main content
15,885,897 members
Articles / Web Development / HTML

Weather Information Report Chart in Java

Rate me:
Please Sign up or sign in to vote.
4.91/5 (6 votes)
7 Jan 2015CPOL3 min read 35.7K   1.7K   7   2
Weather Information Report Chart in Java

Introduction

This project describes how to show weather report of a particular location according to date and time in line chart, i.e., display data in graphical format.

Step 1

First of all, we will have to get weather report data according to location and date. Like suppose we want to know weather condition of London on 31-12-2014.

Weather Underground Server of Airport of England will help us to get weather information according to location and date.

How to get it?

www.wunderground.com will give us data. And the requested URL is

http://www.wunderground.com/history/airport/AAAA/YYYY/MM/DD/DailyHistory.html?HideSpecis=1&format=1

where AAAA=”Location Code of that area” and YYYY/MM/DD is date format. Then it will return data in string format. We will have to parse that data according to our requirements and will have to use respective records in displaying in graphical format.

You can see the returned data from server in your web page by this URL.

http://www.wunderground.com/history/airport/EGLL/2014/12/31/DailyHistory.html?HideSpecis=1&format=1

Step 2

After this, there would be some missing records in returned data and errors also like -9999.0, N/A, “”,-9999 and variable, etc. So we will have to normalize the records also.

Suppose if record is not available for selected location and time, then we will have to handle this problem too.

Step 3

Now we will have to separate records according to our requirements like suppose we want to display only temperature variation over time, then we will have to collect temperature value according to its time frame. Similarly, we will have others also like wind speed, atmospheric pressure and others as well.

Step 4

Now show the data in graph.

Demo

  1. When the program starts, first frame appears with location and date selection.

    Location string contains Location which binds in JComboBox. JDateChoose is library file that is third party tool used in selecting date (you can see it and date format).

    Image 1

  2. Date chooser is like this:

    Image 2

  3. When you click on Get Information button, New frame appears that shows graph like this:

    Image 3

  4. If you want to see more specific data, you will have to zoom in graph by holding left mouse click and drag down the mouse. In this graph, you can see specific data about pressure for the above graph.

    Since graph line is straight in the above graph while in this graph not.

    Image 4

Code

Image 5

A snap of WeatherGUI.Java file:

  1. JFrame ’a’ and JFrame ‘b’ is declared here which are main frame for this project.
  2. A function called MainINterface() is used to call in main method while load program this contain frame a in which date chooser and select location operation is performed. When button click operation fired, it validates data like date is in range and in correct format. You can see in the following image. Applied on JFrame ‘a’.

    Image 6

  3. When button click event is fired, then it will have to validate date and location, it can be seen in the following image:

    Image 7

  4. If everything is okay, then it is time to make URL string to get data from weather underground server and send it a method that gets data and parses it according to respective category and add in ArrayList md’. But here, we will have to take care of data validation and control like -9999.0, N/A,-9999 and Null. So here, we are storing 0 of data is anything like them.

    Image 8

  5. Now if no such data is available for selected location and date, then we will have to check it also so here if md.size<36 then no data is available.

    Image 9

  6. Now we have separate ArrayList for every time, temperature, pressure, wind speed and precipitate so we will have to get all data from ‘mdArrayList and will have to assign corresponding value in these array lists.

    Image 10

  7. Now this time to draw chart so draw_chart() is method for this work. This method wants JFreeChart a third party library from Oracle.

    Image 11

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Sequence IT Solution
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionexecute Pin
Member 1384899028-May-18 22:21
Member 1384899028-May-18 22:21 
Generalsuper Pin
bk33448-Jan-15 1:56
bk33448-Jan-15 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.