Wont display my second set of numbers

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:

Hi magic_moose,

A .csv file separates columns by commas. A .tsv file separates columns by tabs. Your file separates columns by both. Does splitting data[i] by ",\t" instead of "," change the result?

Best,

2 Likes

Another question I had was do you know how to get rid of the black between my graph line?

Another options is to use replace:

String / Reference / Processing.org
String (Java Platform SE 6)

I believe splitTokens could do the job as well.

For the second question, to remove the black color under the curve, you need to call noFill(); at the beginning of: drawGraph()

Kf