Trouble with graph

Where you get the data from doesn’t matter. What counts is that you have - somehow - an array of points. here’s an example that show what I mean by drawing lines between points.

int[] x_values = { 20, 30, 40, 50, 60, 80, 100};
int[] y_values = { 20, 40, 100, 20, 100, 80, 140 };

void setup(){
  size(600,400);
}

void draw(){
  background(0);
  stroke(255,0,0);
  for( int i = 0; i < x_values.length - 1; i++){
    line( x_values[i], y_values[i], x_values[i+1], y_values[i+1] );
  }
}

Notice that this is not drawing a PShape. It is just drawing several lines. Also notice the upper limit on the loop is one less than the arrays’ lengths, since there is no way to draw a line from the last point (where would you draw it to?).

1 Like