//create variables float values[] = new float[152] ; //arrx float dates[] = new float[152] ; //arry float l1[] = new float[152] ; // l1 array float l2[] = new float[152] ; // l2 array String countries[] = new String[152]; // seitosa, versicolor, virginica int xscaleFactor = 30; // scale int yscaleFactor = 30; float colorArr[] = new float[152] ; float minColor = 10000.0, maxColor = -10000.0 ; int lim = 0 ; String xAxis = "Sepal Width"; //set the x axis to sepal width String yAxis = "Sepal Length"; //set the y axis to sepal length int yData = 0; // data on y axis int xData = 1; // data on x axis //size of dots variables int changeSize = 1; float shapeSize; void setup() { size( 600, 600 ); // size of program 600x600px background( 255 ); // bg is white // read excel file and put into lines array String lines[] = loadStrings( "data.csv" ); //IAT355_Sample_Asst2.pde IAT355_Sample_Asst2.pde for (int i=0; i < 152 && i < lines.length ; i++ ) { String[] numbers = split( lines[i], "," ); // split array after each comma for( int j = 0 ; j < numbers.length ; j++ ) { //print(numbers[j] + ", " ); if( j == 0 ) { values[i] = float(numbers[j]); // pass 1st column into values array } if( j == 1 ) { dates[i] = float(numbers[j]); // pass 2nd column into dates array } if( j == 2 ) { l1[i] = float(numbers[j]); // pass 3rd column into l1 array /*colorArr[i] = numbers[j] ; if( colorArr[i] > maxColor ) maxColor = colorArr[i] ; if( colorArr[i] < minColor ) minColor = colorArr[i] ;*/ } if ( j == 3 ) { l2[i] = float(numbers[j]); // pass 4th column into l2 array //l1[i] = numbers[j] ; } if ( j == 4 ) { countries[i] = numbers[j]; // pass 5th column into countries array } lim = i+1 ; println(); } //println ( "Min, Max color = " + minColor + " , " + maxColor ); } smooth(); // anti-aliases the pic so doesn't look pixelated } void draw() { pushMatrix(); background(255); translate(width/2-100, height/2+30); //moves entire grid to a point for(int i = 0; i < 151; i++) { // send arrays to ScatterPlotPoint class ScatterPlotPoint beh = new ScatterPlotPoint(dates[i], values[i], l2[i], l1[i], countries[i], xAxis, yAxis, changeSize, shapeSize); beh.getGraphData(0, 0, 290, 290); //grab graph data beh.plot(xscaleFactor, yscaleFactor); //plot the points to scale } ScatterPlotAxis meh = new ScatterPlotAxis(0, 0, 290, 290, xAxis, yAxis); // send points to graph class fill(0); // black font //PFont font; // load font //font = loadFont("Verdana-48.vlw"); // load Verdana font //textFont(font, 14); // set font size to 14 text ("value" + " vs. " + "date", 40, -280); // graph title according to buttons //automatic scaling float xMax = 10; //10 max axis marks float yMax = 10; float yInc = 28.5; //increments float xInc = 28.5; if(xAxis.equals("Sepal Width")) { xMax = 5; xInc = 28.5*2; //scale sepal width on x axis by 2x } if(yAxis.equals("Sepal Width")) { yMax = 5; yInc = 28.5*2; //scale sepal width on y axis by 2x } if(xAxis.equals("Petal Width")) { xMax = 3.33; xInc = 28.5*3; //scale petal width on x axis by 3x } if(yAxis.equals("Petal Width")) { yMax = 3.33; yInc = 28.5*3; //scale sepal width on y axis by 3x } for(int i = 0; i <= yMax; i++ ){ text(i, -30, -(i*yInc)); // make numbers for y axis 0-9 } for(int i = 0; i <= xMax; i++ ){ text(i, (i*xInc), 25); // make numbers for x axis 1-9 } //set titles for x and y axis pushMatrix(); translate(-200,-170); rotate(-PI/2); //rotate y axis title by 90 degrees text(yAxis,-100,150); popMatrix(); text(xAxis,100,50); // Legend Text text("Aus/USA", -100, 50); // label Legend text("Brit/USA", -100, 75); // dark colour and large text("Can/USA", -100, 100); // dark colour and large text("Dutch/USA", -100, 125); // dark colour and large text("Fren/USA", -100, 150); // label Legend text("GRE/USA", -100, 175); // dark colour and large text("JAP/USA", -100, 200); // dark colour and large text("Swiss/USA", -100, 225); // dark colour and large //text("x", 0,0); // where 0,0 is for reference // Legend Dots fill(255, 82, 82); ellipse(-120, 45, 20, 20); fill(195, 18, 198); ellipse(-120, 70, 20, 20); fill(71, 25, 227); ellipse(-120, 95, 20, 20); fill(9, 207, 227); ellipse(-120, 120, 20, 20); fill(15, 170, 58); ellipse(-120, 145, 20, 20); fill(232, 221, 0); ellipse(-120, 170, 20, 20); fill(100, 27, 24); ellipse(-120, 195, 20, 20); fill(183, 70, 114); ellipse(-120, 220, 20, 20); meh.drawGraph(); // draw the graph popMatrix(); //clear previous matrix }