Final Processing Code!
In processing, we decided to code a data. We coded a bar graph, a data visualization of wine and grapes. Data talks about if grapes has affected the price of wine. We pulled the data online and uploaded in processing.

CODE:
//ap.data.3.Food.txt
Table foodTable = null;
color barColor = #63EAFF;
color highlightColor = #360524;
float dataTipX = 0;
float dataTipY = 0;
int dataTipYear = 0;
float dataTipPrice = 0;
void setup () {
size(900, 500);
foodTable = loadTable( “ap.data.3.Food.txt”, “header,tsv” ); // tsv-tab seperated value
foodTable.trim(“series_id”);
} // setup()
void draw () {
background(255);
float barWidth = 8;
float x = 0;
int startYear = 1996;
String seriesId = “APU0000720311”;
drawBars( foodTable, seriesId, x, barWidth, startYear );
seriesId = “APU0000711417”;
drawBars( foodTable, seriesId, x+barWidth, barWidth, startYear);
if ( dataTipX > 0 ) {
drawDataTip (dataTipX, dataTipY, dataTipYear, dataTipPrice);
}
dataTipX = -1;
dataTipY = -1;
}
void drawBars(Table foodTable, String seriesId, float x, float barWidth, int startYear ) {
int i=1;
int numMonths = 12;
float averagePrice = 0;
for ( TableRow row : foodTable.findRows( seriesId, “series_id” )) {
int year = row.getInt(“year”);
if ( year >= startYear ) {
float price = row.getFloat(“value”);
averagePrice += price;
if ( i % numMonths == 0 ) {
averagePrice /= 12; //averagePrice = averagePrice / 12
String month = row.getString(“period”);
float h = averagePrice * 30;
float y = height — h;
fill( barColor);
setHighlight( x, y, barWidth, h);
rect(x, y, barWidth, h);
dataTip( x, y, barWidth, h, year, averagePrice);
x = x+20;
averagePrice = 0;
}
i++;
}
} // for loop
} //drawbars
void setHighlight( float x, float y, float barWidth, float h) {
if (mouseX < x +barWidth && mouseX > x && mouseY < y+h && mouseY > y) {
fill(highlightColor);
}
}
void drawDataTip ( float x, float y, int year, float price ) {
fill(255);
rect (x, y, 100, 60);
fill(0);
text ( year, x+5, y+15);
text ( price, x+40, y+15);
}
void dataTip( float x, float y, float barWidth, float h, int year, float price) {
if (mouseX < x +barWidth && mouseX > x && mouseY < y+h && mouseY > y) {
dataTipX = mouseX;
dataTipY = mouseY;
dataTipYear = year;
dataTipPrice = price;
}
}