09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 12-1. Tables are grids of cells. Rows are the horizontal<br />

elements and columns are vertical. Data can be read from individual<br />

cells, rows, and columns.<br />

Table data is often stored in plain-text files with columns using<br />

commas or the tab character. A comma-separated values file is<br />

abbreviated as CSV and uses the file extension .csv. When tabs<br />

are used, the extension .tsv is sometimes used.<br />

To load a CSV or TSV file, first place it into a sketch’s data folder<br />

as described at the beginning of Chapter 7, and then use the<br />

loadTable() function to get the data and place it into an object<br />

made from the Table class.<br />

Only the first few lines of each data set are shown in<br />

the following examples. If you’re manually typing the<br />

code, you’ll need the entire .csv, .json, or .tsv file to<br />

replicate the visualizations shown in the figures. You<br />

can get them from an example sketch’s data folder<br />

(see “Examples and Reference” on page 11).<br />

The data for the next example is a simplified version of Boston<br />

Red Sox player David Ortiz’s batting statistics from 1997 to<br />

2014. From left to right, it lists the year, number of home runs,<br />

runs batted in (RBIs), and batting average. When opened in a<br />

text editor, the first five lines of the file looks like this:<br />

1997,1,6,0.327<br />

1998,9,46,0.277<br />

1999,0,0,0<br />

Data 167

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!