// sketch that reads the a txt file with // raw data as the ones generated by FreqQueryTotxt // and plot it on a one dimensional bar graph // The file has to be on the data directory of the sketch int [] BarData = new int[48]; float plotX1, plotY1; float plotX2, plotY2; float labelX, labelY; // Month labels for 4 years of data String [] Hourslabel = {"J","F","M","A","M","J","J","A","S","O","N","D","J","F","M","A","M","J","J","A","S","O","N","D","J","F","M","A","M","J","J","A","S","O","N","D","J","F","M","A","M","J","J","A","S","O","N","D"}; int MaxScale =0; PFont font; void setup() { size(900,300); font = loadFont("UniversLTStd-Cn-14.vlw"); // Name of the external file String TheFile = "2012.txt"; String lines[] = loadStrings(TheFile); // Going line by line // Filling and finding the maximum for (int i=0; i < lines.length; i++){ BarData[i] =int(lines[i]); if (BarData[i] >MaxScale){ MaxScale =BarData[i]; } println(i + " " +BarData[i]); } // Setting the margins plotX1 = 60; plotX2 = width - 30; labelX = 30; plotY1 = 30; plotY2 = height - 40; labelY = height - 20; } void draw(){ // Plotting the bargraph drawBar(); } void drawBar(){ float Hside; float Vside; float PointX,PointY; background(230); strokeWeight(1); Hside = (plotX2-plotX1)/48; Vside = (plotY2-plotY1); fill(160); noStroke(); // stroke(0); for (int i =0;i<48;i++){ float NewHeigh = map(BarData[i],0,MaxScale,0,Vside); rect(plotX1+i*Hside, plotY2-NewHeigh,floor(Hside*.94),NewHeigh); } // // Labeling //Horizontal textFont(font); fill(178); for (int h =0;h<48;h++){ textAlign(CENTER,CENTER); text(Hourslabel[h],plotX1 + Hside*(h+.5),plotY2+20); } // Vertical labels textAlign(CENTER,CENTER); for(int vl =0; vl<= 10 ; vl++){ PointY = map(vl,0,10,plotY1,plotY2); PointX = labelX; text(int(MaxScale -vl*MaxScale/10),PointX,PointY); } }