Community Growth Web - Coeur d'Alene, ID

Graphing Comma-Separated Numbers
from a Text File

Text from a file can be used to generate a simple visualization. Take the following data file. 

The results of visualizing this data are shown below.

Graphing Comma-Separated Numbers from a Text File 

int[] data;  void setup() {   
size(200, 200);   
// Load text file as a String   
String[] stuff = loadStrings("data.csv");   
// Convert string into an array of integers using ',' as a delimiter   
data = int(split(stuff[0], ',')); }  

void draw() {   
for (int i = 0; i<data.length; i++) {    	
// Use array of ints to set the color and height of each rectangle.     
rect(i*20, 0, 20, data[i]);   

Looking at how to parse a csv file with split() was a nice learning exercise. In truth, dealing with csv files (which can easily be generated from spreadsheet software such as Google docs) is such a common activity that Processing has an entire built-in class called Table to handle the parsing for you.