Data visualization assignment with Processing

From Knowledge Kitchen
Jump to navigation Jump to search

Using data from any free online data source, create a data visualization using Processing.

  • You may use the same data set from a previous assignment, if you would like.
  • You may work with up to one other student on this project. If you do so, include their name in the email when you submit your assignment.
  • Your assignment cannot use the same data set as any other student's assignment



You must document your code using javadoc comments for all classes, instance attributes, and instance methods.

Custom class

Your code must include a custom class that holds all the data need to represent a single data object from your data set. Make an array of objects from this class to hold your entire data set.

For example, if you were using a data set representing donors to NYC election candidates for public office, somewhere in your code, you might create a custom class named Donor to encapsulate all the attributes and actions related to each donor. And you could create an array of those objects to represent the entire data set, which would make it easy to loop through them all and perform actions on each of them.

Overloaded constructors

Your custom class must contain at least 2 overloaded constructor methods, in addition to a default no-arg constructor.

Object orientated principles

  • Your code must follow the principles of abstraction and encapsulation.
  • Use getter and setter methods for any data fields that require external access.


Users must be able to interact with your data visualization in some way and have the visualization react meaningfully. Common interactions include clicking, hovering the mouse over a part of the visualization, or typing on the keyboard.

Following our example of campaign donors, our visualization may display a circle representing each donor, with the size of the circle being proportional to how much they donated. Hovering over the circle could expand it and display more information about the donor and the candidate they donated to.

Code hints

Example of creating an array of custom objects from within your main program

//initialize an array of your custom data type
Donor[] donors = new Donor[200];
//loop through the array and create a Donor object to hold at each position in the array
for (int i=0; i<donors.length; i++) {
    //instantiate a donor and store at this position in array
    donor[i] = new Donor( put your class's required constructor arguments here );

Example of defining a custom class

Your custom Donor class might be defined with data fields such as name, address, borough, the name of the candidate they donated to, how much they donated, etc. The class might have a method to draw itself to the screen.

class Donor {
    //instance variables
    String name;
    String address;
    String borough;
    String candidateName;
    double donationAmount;

    Donor(String n, String, a, String b, String c, double d) { = n;
        this.address = a;

    void show() {
         //make it show up as a shape in the Processing window at the proper location
         //creativity is rewarded

Example of making all objects draw themselves to the screen from within your main program

//loop through all donors and make them appear on the screen
for (int i=0; i<donors.length; i++) {
     Donor thisDonor = donors[i]; //make a shortcut variable to point to the current donor; //make this donor draw itself to the screen

Useful or inspirational links

Example data sources

What links here