I am trying to use a TSV data file to plot on a graph however the second collum of data isnt being recognized. Can someone Help?
Here is my Code so far:
PFont font;
float x1, y1, x2, y2;
int[]fireData;
int[]years;
int mostFires;
int leastFires;
void setup(){
size(500,500);
font = loadFont(“berlin30.vlw”);
textFont(font);
x1 = 40;
y1 = 90;
x2 = width- x1;
y2 = height - y1;
smooth();
//read the data table
String[] data = loadStrings(“Califires.tsv”);
fireData = new int [data.length];
years = new int [data.length];
for(int i=0; i<data.length; i++){
String[] pieces = split(data[i], “,”);
years[i] = int(pieces[0]);
fireData[i] = int(pieces[1]);
}
println(“How many years: “+years.length+””);
println(fireData);
mostFires = max(fireData);
leastFires = min(fireData);
}
void draw(){
background(11, 224, 144);
rectMode(CORNERS);
noStroke();
fill(255, 237, 223);
rect(x1, y1, x2, y2);
fill(8, 4, 4);
text(“Fires in California through the years”, x1, y1-20);
drawGraph(fireData, mostFires, leastFires, #FF1E06, “F”);
}
void drawGraph(int[] data, int yMin, int yMax, color sColor, String label){
float x=0;
float y=0;
stroke(sColor);
strokeWeight(2);
beginShape();
for(int i=0; i<data.length; i++){
x = map(i,0, data.length-1, x1, x2);
y = map(data[i], yMin, yMax, y2, y1);
vertex(x,y);
}
endShape();
if(sColor == color(#000000)){
sColor = color(#EEEEEE);
}
fill(sColor);
textAlign(LEFT);
text(label, x+10, y);
noFill();
}
When I run the println it only show’s 0 for the data which should be large numbers.
Here is the tsv file: