How do I make these rows and columns (csv to grid) work?

I don’t have the table file (csv) so I work with a random size. But then it works.
So I assume your error has to do with the table.
In which line does the error occur? That’s important.

I guess it’s TableRow row = data.getRow(index); ?

Then you would read over the end of the file (read a line more than there is)

Are there 365 lines?

  • Basically, say println(index); before that line TableRow row = data.getRow(index); and check where it breaks

Make an if-clause inside the for loop if( index < data.getRowCount()) {…what you have here now…}
to prevent the code from being executed, when we read through the end of the file

(Sometimes those files have an empty line at its end. Bad. Crash.)

Warm regards,

Chrisir

P.S.

Here is my running code


Table data;

int cols = 73;
int rows = 5;

// 40 wide, 25 down
// determin our rows and columns
float circleScalar = 0.1;
// ^ Adjusts the fit of circles in the grid

void setup() {
  size(1000, 600);
  background(255);
  data = loadTable("FitBit Data - steps - 2019.csv", "header");
  noLoop();
  // data counting variable to move down the rows 1, 2, 3, 4…
}

void draw() {
  // width divided by columns
  float grid = width/cols;
  //translate(grid/2, grid/2);
  fill(0, 64);
  noStroke();
  int index = 0;
  // for int y = 0, y is less than rows
  for (int y = 0; y < rows; y++) {
    for (int x = 0; x < cols; x++) {
      // TableRow row = data.getRow(index);
      //float d = row.getFloat("steps");
      float d = random(9188); 
      float circleSize = getFixedCircleSize(d);
      stroke(0);
      ellipse(22+x*grid, 33+y*grid*1.5, 
        circleSize, circleSize);
      // Multiplied to allow space underneath for text
      index++;
    }
  }
}

// Helper function
float getFixedCircleSize(float _size) {
  float s = sqrt(_size)*circleScalar;
  return s;
}
1 Like