import de.bezier.data.sql.*; // function that reads The IDs from a txt file and use them // to make a query int mCount=0; MySQL msql; int [] a2009 = new int[12]; float plotX1, plotY1; float plotX2, plotY2; float labelX, labelY; String [] Hourslabel = {"J","F","M","A","M","J","J","A","S","O","N","D"}; PFont font; void setup() { size(900,300); font = loadFont("UniversLTStd-Cn-14.vlw"); // connecting to the database String user = "mat259"; String pass = "V1sual1zat1on"; String database = "spl_all"; String TheQuery =""; // String TextToSearch ="pumpkin"; String TextToSearch ="NBA"; String TheFile = "2009Monthly.txt"; String lines[] = loadStrings(TheFile); msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass ); if ( msql.connect() ) { for (int k =0 ; k < 12; k++){ TheQuery="SELECT count(*) FROM transactionsallID WHERE id BETWEEN " + lines[2*k] + " and " + lines[2*k+1] ; TheQuery+= " and (title like '%" + TextToSearch + "%')"; msql.query( TheQuery); msql.next(); a2009[k]= msql.getInt(1); println(k + " " + msql.getInt(1)); } } else { println(" connection failed "); } plotX1 = 30; plotX2 = width - 30; labelX = 20; plotY1 = 30; plotY2 = height - 40; labelY = height - 20; } void draw(){ drawBar(); } void drawBar(){ float Hside; float Vside; int MaxScale =0; background(230); strokeWeight(1); Hside = (plotX2-plotX1)/12; Vside = (plotY2-plotY1); // finding the maximun to adjust the scale: for (int k=0;k<12;k++){ if (a2009[k] > MaxScale){ MaxScale = a2009[k]; } } fill(160); stroke(0); //The total for (int h =0;h<12;h++){ float NewHeigh = map(a2009[h],0,MaxScale,0,Vside); rect(plotX1+h*Hside, plotY2-NewHeigh,floor(Hside*.95),NewHeigh); } // Labeling textFont(font); fill(128); for (int h =0;h<12;h++){ textAlign(CENTER,CENTER); text(Hourslabel[h],plotX1 + Hside*(h+.5),plotY2+20); } }