10.24 Share some Code

Transforming Data: Cultural Strategies in DataMining
Instructor: George Legrady
glegrady
Posts: 203
Joined: Wed Sep 22, 2010 12:26 pm

10.24 Share some Code

Post by glegrady » Sun Oct 23, 2011 12:16 pm

Please post here a small code that uses MySQL and visualizes some results from data
Last edited by glegrady on Sun Oct 30, 2011 8:50 pm, edited 1 time in total.
George Legrady
legrady@mat.ucsb.edu

User avatar
matthew
Posts: 11
Joined: Tue Sep 13, 2011 11:13 am
Location: brooklyn, ny

stacking colored blocks based on quantity

Post by matthew » Mon Oct 31, 2011 12:05 pm

Here is some code that will create a series of stacked blocks based on a count of books you get from mySQL. It changes the color of each block so that the quantity becomes highlighted. I've stripped out the mySQL and other elements so it is easier to follow.

// init variables
int colorS, colorB, colorA;
int vizW, vizH, yStep;
int count2010

void setup() {

// color
colorMode(HSB, 100);
colorS = 50; // saturation
colorB = 50; // brightness
colorA = 50; // opactity

// rectangle attributes
rectMode(CENTER);
vizW = 119;
vizH = 3;
xPos = 50;
yPos = 0;

// distance between center of each rectangle
yStep = 4;

count2010 = 100; // count of books from mySQL

}

void draw() {

for (int i = 0; i < count2010; i++ ) {

// change the color for each rectangle
// i increments the color or hue of each
fill(i,colorS,colorB,colorA);

// change the position for book rectangle
// starting position + i time our step set above
int thisY = posY+i*yStep;

// draw rectangle
rect(xPos,thisY,vizW,vizH);
}

}

User avatar
matthew
Posts: 11
Joined: Tue Sep 13, 2011 11:13 am
Location: brooklyn, ny

stack books and hover for titles

Post by matthew » Mon Oct 31, 2011 12:18 pm

/*
Here is the full code. It grabs the titles for each year for a specific dewey number. It creates a stack of blocks to represent each title for each year. Hovering over the block shows the title.
*/

// init mySQL
import de.bezier.data.sql.*;
MySQL msql;
boolean useDB = true;


// init variables
int colorH, colorS, colorB, colorA;
int yearX, bankY, ellipseY, textX, textY, sizeFactor;
int tooltipY, vizW, vizH, yStep;
int count2010, count2009, count2008, count2007, count2006, count2005;

String[] titles2010 = new String[0];
String[] titles2009 = new String[0];
String[] titles2008 = new String[0];
String[] titles2007 = new String[0];
String[] titles2006 = new String[0];
String[] titles2005 = new String[0];

// tooltip
float closestDist;
String closestText;
float closestTextX;
float closestTextY;


void setup() {
// setup canvas
size( 900, 800 );
colorMode(HSB, 100);
smooth();
textAlign(CENTER);
noStroke();
smooth();
background(95);

// background for year labels
rectMode(CENTER);
fill(0,0,100);
rect(width/2,height/2,width,30);

// viz common attributes
colorH = 30;
colorS = 50;
colorB = 50;
colorA = 50;
yearX = 120; // year columns
bankY = height/2 + 25; // title start coord
ellipseY = height/2;
textX = 2; // nudge
textY = height/2 +5;
sizeFactor =9;
tooltipY = height/2 - 50;
vizW = 119;
vizH = 3;
yStep = 4;

// draw year labels
fill(20);
text("2010", yearX * 6 + textX, textY);
text("2009", yearX * 5 + textX, textY);
text("2008", yearX * 4 + textX, textY);
text("2007", yearX * 3 + textX, textY);
text("2006", yearX * 2 + textX, textY);
text("2005", yearX * 1 + textX, textY);

// setup mySQL
String user = "mat259";
String pass = "V1sual1zat1on";
String database = "spl_years";
// if needed add additional parameters like this:
// bildwelt?useUnicode=true&characterEncoding=UTF-8


/******************
full mySQL query

select
title, deweyClass, ckinDateTime, ckoutDateTime,
DAYOFYEAR(ckinDateTime) - DAYOFYEAR(ckoutDateTime) as duration,
barcode, callNumber, subject1, subject2, subject3
from
transactionsall
where
YEAR(ckoutDateTime) > 2005 # removing old and errant entries
&& SUBSTRING(deweyClass,1,8) = 346.7307 # focusing on personal law
&& (
SUBSTRING(deweyClass,9,1) = 7
OR SUBSTRING(deweyClass,9,1) = 8
) # examining the range
&& DAYOFYEAR(ckinDateTime) - DAYOFYEAR(ckoutDateTime) > 0 # removing errant entries
order by
DAYOFYEAR(ckinDateTime) - DAYOFYEAR(ckoutDateTime) desc # sorting

END full mySQL quiery
*********************/


// connect to database of server tango
if ( useDB ) {
msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );
println( "using mySQL");
}

// query database
if ( useDB && msql.connect() ) {
println( "mySQL success!");

// 2010
msql.query( "SELECT title FROM transactions2010 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title"); // access by col number (2) or ("fuid")
// int n = msql.getInt("fuid");
titles2010 = append(titles2010, thisTitle);
}
count2010 = titles2010.length;
println("2010 titles: " + titles2010.length );


// 2009
msql.query( "SELECT title FROM transactions2009 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title");
// int n = msql.getInt("fuid");
titles2009 = append(titles2009, thisTitle);
}
count2009 = titles2009.length;
println("2009 titles: " + count2009 );


// 2008
msql.query( "SELECT title FROM transactions2008 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title");
titles2008 = append(titles2008, thisTitle);
}
count2008 = titles2008.length;
println("2008 titles: " + count2008 );


// 2007
msql.query( "SELECT title FROM transactions2007 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title");
titles2007 = append(titles2007, thisTitle);
}
count2007 = titles2007.length;
println("2007 titles: " + count2007 );


// 2006
msql.query( "SELECT title FROM transactions2006 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title");
titles2006 = append(titles2006, thisTitle);
}
count2006 = titles2006.length;
println("2006 titles: " + count2006 );


// 2005
msql.query( "SELECT title FROM transactions2005 WHERE SUBSTRING(deweyClass, 1,9) = 346.73077" );
while (msql.next()) {
String thisTitle = msql.getString("title");
titles2005 = append(titles2005, thisTitle);
}
count2005 = titles2005.length;
println("2005 titles: " + count2005 );

} // END if ( useDB && msql.connect() )

else { println( "mySQL not connected "); }


// find max & min values
float[] list = { count2006, count2007, count2008, count2009, count2010 };
float yearMax = max(list);
float yearMin = min(list);
println(" max: "+ yearMax + "\n min: " + yearMin);

// static data for testing
if ( !useDB ) {
println("using local data");
count2010 = 11 * sizeFactor;
count2009 = 9 * sizeFactor;
count2008 = 8 * sizeFactor;
count2007 = 5 * sizeFactor;
count2006 = 2 * sizeFactor;
count2005 = 1 * sizeFactor;
} // END if (!useDB)

} // END setup()

void draw() {
// background for bankruptcy viz refresh
rectMode(CORNER);
fill(95);
rect(0, height/2+15, 900, height/2-15);

// background for tooltip
fill(95);
rectMode(CENTER);
rect(width/2,tooltipY, 900, 30);

// tooltip - set closestDistance out of the frame
closestDist = width*height;

/* build as loop
// int[] countYear = { count2006, count2007, count2008, count2009, count2010 };
// Array[] titleYear = { titles2006,titles2007,titles2008,titles2009,titles2010 };
println( "countYear: " + countYear[2] );
println( "titleYear: " + titleYear[2] );
*/

for (int i = 0; i < count2010; i++ ) {
float thisX = yearX * 6;
float thisY = bankY+i*yStep;
String thisTitle = titles2010;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}

for (int i = 0; i < count2009; i++ ) {
float thisX = yearX * 5;
float thisY = bankY+i*yStep;
String thisTitle = titles2009;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}

for (int i = 0; i < count2008; i++ ) {
float thisX = yearX * 4;
float thisY = bankY+i*yStep;
String thisTitle = titles2008;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}

for (int i = 0; i < count2007; i++ ) {
float thisX = yearX * 3;
float thisY = bankY+i*yStep;
String thisTitle = titles2007;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}

for (int i = 0; i < count2006; i++ ) {
float thisX = yearX * 2;
float thisY = bankY+i*yStep;
String thisTitle = titles2006;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}

for (int i = 0; i < count2005; i++ ) {
float thisX = yearX * 1;
float thisY = bankY+i*yStep;
String thisTitle = titles2005;
rectMode(CENTER);
fill(i,colorS,colorB,colorA);
rect(thisX,thisY,vizW,vizH);
// text to tooltip
tooltip(thisTitle, thisX, thisY);
}



// tooltip
// Use global variables set in drawData()
// to draw text related to closest item.
if (closestDist != width*height) {
fill(0);
textAlign(CENTER);
// text(closestText, closestTextX, closestTextY + 40);
text(closestText, width/2, tooltipY);
cursor(HAND);
} else { cursor(ARROW); }

} // END draw()



void tooltip(String title, float x, float y) {

int radius = 4;
int h = vizH/2+1;
int w = vizW/2;

float d = dist(x, y, mouseX, mouseY);

float dx = dist(x, 0, mouseX, 0);
float dy = dist(0, y, 0, mouseY);

// Because the following check is done each time a new
// circle is drawn, we end up with the values of the
// circle closest to the mouse.
//if ((d < radius + 2) && (d < closestDist)) {
if ((dx < w) && (dy < h) && (d < closestDist)) {
closestDist = d;
// String title = title;
closestText = title;
closestTextX = x;
closestTextY = y-4;
// println ("tooltip: " + x + ", " + y + ", " + title);

}


} // END tooltip

putzb642
Posts: 10
Joined: Tue Sep 13, 2011 11:02 am

Re: 10.24 Share some Code

Post by putzb642 » Mon Nov 07, 2011 6:28 am

//Here is updated code. Searching for the rate of books involving "communication". The color of the bars are dependent on the size of them. Inside of the bar there is a display of the amount of check outs for that specific month.//

//code


import de.bezier.data.sql.*;

MySQL msql;

void setup()
{
size( 600, 400 );
background(0);

String user = "mat259";
String pass = "V1sual1zat1on";

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2008 where title like '%communication%' group by month(ckoutDateTime) order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

colorMode(HSB);
fill(count, count, 150 , 100);
stroke(0 ,50);
rect( monthCount * (width/12) , 300 , width /12 , count-height);

fill(255);
textAlign(CENTER);

pushMatrix();
translate(20, 275);
rotate(HALF_PI);
rotate(HALF_PI);
rotate(HALF_PI);
textSize(20);
text(count,10, 30+ monthCount * (width/12));
popMatrix();

textSize(13);
text(monthCount+1, 20+ monthCount * (width/12) , 350);
text("Month", width/2, 375);
textSize(20);
text("Communication in 2008", width/2, 50);

//println("mountCount "+monthCount);
monthCount++;

}



}
else
{
println( "Conection Failed!! ");
}
}

lazad518
Posts: 8
Joined: Tue Sep 13, 2011 11:01 am

Re: 10.24 Share some Code

Post by lazad518 » Mon Nov 07, 2011 6:50 am

Hey, so here is my attempt. I tried to create two sets of flying elipses that move around dependent on the amount of transactions in the year. So its 2007 vs 2008, and 2007 is white circles and 2008 is blue circles. As I've mentioned, my serious lack in coding was a major set back and I cannot get this to work. I spent a lot of time on this already, and I'm completely confused. So this is how far I got:


import de.bezier.data.sql.*;

MySQL msql;

void setup()
{
size( 5000, 5000 );
background(255);

String user = "mat259";
String pass = "V1sual1zat1on";

/*String [] monthLables = new String[12];
monthLables[0] = "Jan";
monthLables[1] = "Feb";
monthLables[2] = "Mar";
monthLables[3] = "Apr";
monthLables[4] = "May";
monthLables[5] = "Jun";
monthLables[6] = "Jul";
monthLables[7] = "Aug";
monthLables[8] = "Sep";
monthLables[9] = "Oct";
monthLables[10] = "Nov";
monthLables[11] = "Dec";*/
// regular way of defining an array

String [] monthLables = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{

msql.query( "select month(ckoutDateTime), count(*) from transactions2007" );

int monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

fill(255 , 50);
stroke(0 ,50);
ellipse(x[35], y[35], 35, 35);
x =speed[monthCount] +x[monthCount];
y =speed2[monthCount] +y[monthCount];

msql.query( "select month(ckoutDateTime), count(*) from transactions2008" );

int monthCount1 = 0;

while(msql.next()) {

int amonth = msql.getInt(3);
int count = msql.getInt(4);

fill(25, 25, 112);
stroke(0 ,50);
ellipse(x[35], y[35], 35, 35);
x =speed[monthCount1] +x[monthCount1];
y =speed2[monthCount1] +y[monthCount1];

for(int monthCount =0; monthCount<maxlimit; i++)
{
//so circles bounce off left and right side of the screen and change speed as they do so
if(x[monthCount]>5000){
speed[monthCount]= - monthCount (-10, 10);
speed2[monthCount]= - monthCount (-10, 10);
// limits the value of x going off screen, and reverses the speed backwards
}else if (x <0) {
speed[monthCount] = monthCount (-10, 10);
speed2[monthCount]= monthCount (-10, 10);
// limits the value of x going off screen again, and revers the speed backwards
}

//so circles bounce off top and bottom ends of the screen and change speed once again

if(y[monthCount]>5000){
speed[monthCount]= - monthCount(-10, 10);
speed2= - monthCount (-10, 10);
}else if (y[monthCount]<0){
speed[monthCount] = monthCount (-10, 10);
speed2[monthCount]= monthCount (-10, 10);
}
}
}
else
{
println( "Conection Failed!! ");
}
}

void draw()
{

}

User avatar
deklerk
Posts: 14
Joined: Tue Sep 13, 2011 11:10 am
Location: New York, NY
Contact:

Re: 10.24 Share some Code

Post by deklerk » Mon Nov 07, 2011 7:18 am

I took MySQL query on the Dewey System's Classification of Items on Religion that I was working on a few weeks ago and performed a small visualization experiment. Not satisfied with it, so definitely welcome ideas. Further explanation is included with the code that I have posted here: http://goo.gl/yKop8
-----
Christo

alessandrarosecampos
Posts: 9
Joined: Tue Sep 13, 2011 11:09 am

Re: 10.24 Share some Code

Post by alessandrarosecampos » Sat Nov 12, 2011 11:28 pm

After unsuccessfully attempting to stray from Sepand's original code, I ultimately stuck quite close to it in order to produce a successful code. I added 'subject1' to the search for the term 'coffee' to expand the results a bit and did a second search for the word 'milk.' In this code, if you click the screen the second bar graph representing the count of the word 'milk' will appear over the 'coffee' graph:


import de.bezier.data.sql.*;



MySQL msql;


void setup()
{
size(400, 400 );
colorMode(HSB, 100);
background(80);
String user = "mat259";
String pass = "V1sual1zat1on";

String [] monthLabels = new String[12];
monthLabels[0] = "Jan";
monthLabels[1] = "Feb";
monthLabels[2] = "Mar";
monthLabels[3] = "April";
monthLabels[4] = "May";
monthLabels[5] = "June";
monthLabels[6] = "July";
monthLabels[7] = "Aug";
monthLabels[8] = "Sept";
monthLabels[9] = "Oct";
monthLabels[10] = "Nov";
monthLabels[11] = "Dec";

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%coffe%' or subject1 like '%coffee%'" + "group by month(ckoutDateTime)order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {
int monthh = msql.getInt(1);
int count = msql.getInt(2);

fill(359, 71, 39);
stroke(0, 50);
rect(monthCount * (width/12), 300, width/12, count -height); //x,y,w,h

fill(0);
textAlign(CENTER);
text(monthLabels[monthCount], 10+ monthCount * (width/12), 350);

//monthCount = monthCount + 1; or:
monthCount++;

}



}
else
{
println( "Conection Failed!! ");
}
}

void draw(){

if (mousePressed) {
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%milk%' or subject1 like '%milk%'" + "group by month(ckoutDateTime)order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {

int monthh = msql.getInt(1);
int count = msql.getInt(2);

fill(355, 4, 93);
stroke(0, 50);
rect(monthCount * (width/12), 300, width/12, count -height); //x,y,w,h


//monthCount = monthCount + 1; or:
monthCount++;
}
}
else
{
println( "Conection Failed!! ");
}
}

User avatar
keats047
Posts: 10
Joined: Tue Sep 13, 2011 11:00 am

Re: 10.24 Share some Code

Post by keats047 » Mon Nov 14, 2011 2:07 pm

Here's my code for the homework:
This code creates two searches using the MySQL database we have been using, taken from the Seattle Public Library. It does an initial search for books on with the term coffee in the title and stacks a second search for politic in the title on top of that. The grey bars are the visualization of politics, the white bars are for coffee.

Stephen Keating

import de.bezier.data.sql.*;

MySQL msql;

void setup()
{
size( 400, 400 );
background(255);

String user = "mat259";
String pass = "V1sual1zat1on";

String [] monthLables = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%coffee%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

fill(255 , 50);
stroke(0 ,50);
rect( monthCount * (width/12) , 300 , width /12 , count -height);

fill(0);
textAlign(CENTER);
text(monthLables[monthCount], 10+ monthCount * (width/12) , 350);

//println("mountCount "+monthCount);
monthCount++;

}


msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%politic%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

count = count/4;

println(count);
fill(128 , 50);
stroke(0 ,50);
rect( monthCount * (width/12) , 300 , width /24 , count -height);

fill(0);
textAlign(CENTER);
text(monthLables[monthCount], 10+ monthCount * (width/12) , 350);

//println("mountCount "+monthCount);
monthCount++;

}

}
else
{
println( "Connection Failed!! ");
}
}

void draw()
{

}
Last edited by keats047 on Mon Nov 14, 2011 2:45 pm, edited 1 time in total.

beth.c.carlson
Posts: 9
Joined: Tue Sep 13, 2011 11:10 am

Re: 10.24 Share some Code

Post by beth.c.carlson » Mon Nov 14, 2011 2:32 pm

This code adds books checked out with the word TEA, as well as some colors

import de.bezier.data.sql.*;

MySQL msql;

void setup()
{
size( 900, 800 );
colorMode(RGB);
background(230);

PFont font;

String s = "COFFEE";
fill(0);
textSize(18);
text(s, 15, height-720, 70, 70);
text("TEA", 15, height-120, 70, 70);

String user = "mat259";
String pass = "V1sual1zat1on";

/*String [] monthLables = new String[12];
monthLables[0] = "Jan";
monthLables[1] = "Feb";
monthLables[2] = "Mar";
monthLables[3] = "Apr";
monthLables[4] = "May";
monthLables[5] = "Jun";
monthLables[6] = "Jul";
monthLables[7] = "Aug";
monthLables[8] = "Sep";
monthLables[9] = "Oct";
monthLables[10] = "Nov";
monthLables[11] = "Dec";*/
// regular way of defining an array

String [] monthLables = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%coffee%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

fill(100 , 50, 20);
stroke(0);
rect( monthCount * (width/12) , height/2 , width /12 , count -height/2);

fill(0);
textAlign(CENTER);
text(monthLables[monthCount], 10+ monthCount * (width/12)+25 , height/2);

//println("mountCount "+monthCount);
monthCount++;

}

msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%tea%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);
count = count/15;
println(count);

fill(100 , 150, 80);
stroke(0);
rect( monthCount * (width/12) , height/2 , width /12 , count );

fill(0);
textAlign(CENTER);
// text(monthLables[monthCount], 10+ monthCount * (width/12) , 350);

//println("mountCount "+monthCount);
monthCount++;

}

}
else
{
println( "Connection Failed!! ");
}
}

void draw()
{

}

bowea324
Posts: 13
Joined: Tue Sep 13, 2011 10:58 am

Re: 10.24 Share some Code

Post by bowea324 » Wed Nov 16, 2011 2:40 pm

import de.bezier.data.sql.*;

MySQL msql;

void setup()
{
size( 600, 600 );
background(255);

String user = "mat259";
String pass = "V1sual1zat1on";

/*String [] monthLables = new String[12];
monthLables[0] = "Jan";
monthLables[1] = "Feb";
monthLables[2] = "Mar";
monthLables[3] = "Apr";
monthLables[4] = "May";
monthLables[5] = "Jun";
monthLables[6] = "Jul";
monthLables[7] = "Aug";
monthLables[8] = "Sep";
monthLables[9] = "Oct";
monthLables[10] = "Nov";
monthLables[11] = "Dec";*/
// regular way of defining an array

String [] monthLables = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)

String database = "spl_years";

msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );

if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%coffee%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

int monthCount = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

fill(255 , 50, 2, 50);
stroke(0 ,50);
rect( monthCount * (width/12) , height , width /12 , count * -0.5);
println(count);

fill(0);
textAlign(CENTER);
text(monthLables[monthCount], 20+ monthCount * (width/12) , 550);

monthCount++;



}

msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%political%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );

int month2Count = 0;

while(msql.next()) {

int amonth = msql.getInt(1);
int count = msql.getInt(2);

fill(255, 0, 0 , 50);
stroke(0 ,50);
rect( month2Count * (width/12) , height , width /12 , count * -0.5);
println(count);

fill(255);
textAlign(CENTER);
text(monthLables[month2Count], 20+ month2Count * (width/12) , 550);

month2Count++;


}


}
else
{
println( "Conection Failed!! ");
}
}

void draw()
{

}

Locked