Download this small csv file with vancouver-temperatures
//Exercise 02 - Plotting temperature on line chart
//Feb 2018 Haig Armen
size(900, 200);
Table myTable = loadTable("vancouver-temperatures.csv", "header");
//PFont myFont;
background(255);
int spacing = 40;
//rect(20, 20, (width-40), (height-40));
//float lastX = 20;
//float lastY = 50;
for (int i = 0; i < myTable.getRowCount(); i = i + 1) {
TableRow myRow = myTable.getRow(i);
int temp = myRow.getInt("temp");
String date = myTable.getString(i, "date");
print(temp + "\n");
noStroke();
fill(0);
ellipseMode(CENTER);
// use the map function to find the right y coordinate to represent temperature
float y = map(temp, 1, 10, 160, 20);
ellipse(i*spacing, y, 5, 5);
noFill();
// wait a minute, this is showing the temperature upsidedown, highest is at the bottom
//float y = map(temp, 1, 10, 160, 20);
// while we're at it, let's calculate the x value too
float x = i*(20+spacing)+80;
//draw a line to connect the dots
stroke(180);
fill(0, 150);
}
Leave a Reply