How can I load the data on page 33 of Ben Fry's Visualizing Data?
in
Programming Questions
•
6 months ago
Hi,
When I run the following below in Processing, I get a grey screen. In the previous step of this project, I was able to display the map.png file.
PImage mapImage;
Table locationTable;
int rowCount;
void setup() {
size(640,400);
mapImage=loadImage("map.png");
locationTable=new Table("locations.tsv");
rowCount=locationTable.getRowCount();
}
void draw(){
image(mapImage,0,0);
smooth();
fill(192,0,0);
noStroke();
for (int row = 0; row <rowCount; row++) {
float x=locationTable.getFloat(row,1);
float y = locationTable.getFloat(row,2);
ellipse(x,y,9,9);
}
}
I have a feeling the proper files aren't able to be accessed with the way I'm grouping them.
My files are organized like this.
test >
data >
locations.tsv
map.png
sketch properties
Table.pde
test.pde
An error message comes up in the console that says "No row named '-1'" repeatedly. It comes from the Table code here:
// find a row by its name, returns -1 if no row found
int getRowIndex(String name) {
for (int i = 0; i < rowCount; i++) {
if (data[i][0].equals(name)) {
return i;
}
}
println("No row named '" + name + "' was found");
return -1;
}
but I don't know why it's happening.
1