Our visualization gets its information from a CSV file — a spreadsheet saved as plain text. In this lesson you'll see how the code fetches that file and turns numbers into 3D bars.

Nuestra visualización obtiene información de un archivo CSV — una hoja de cálculo guardada como texto simple.

1

What Is a CSV? · ¿Qué es un CSV?

CSV stands for Comma-Separated Values. It's just a text file where each line is a row and commas separate columns. Open it in any text editor or spreadsheet app.

# This is what our data looks like in the CSV file:
Label,Population,Percent,Fiscal Year
Spanish Total,87798,21.5,2016-2017
Spanish Limited English,62341,15.2,2016-2017
Chinese Total,28543,6.9,2016-2017

Real Oakland data! 87,798 people speak Spanish — that's 21.5% of Oakland.

LabelPopulationPercentFiscal Year
Spanish Total87,79821.5%2016-2017
Spanish Limited English62,34115.2%2016-2017
Chinese Total28,5436.9%2016-2017
Chinese Limited English18,2344.4%2016-2017
2

How Data Becomes a Bar · ¿Cómo los Datos Se Convierten en una Barra?

Here's the journey data takes from the CSV file to a 3D pedestal:

📄 CSV file on disk
fetch() — browser downloads the file
csvParser.js splits lines & columns
JavaScript array of objects
visualization.js calculates height
🏛 Three.js draws the 3D pedestal
3

The Parser Code · El Código del Analizador

Open docs/js/csvParser.js. The key function is parseCSV(). Here's a simplified version:

// 1. Tell the browser which year we want
const YEAR_FILTER = '2016-2017';

// 2. Download the CSV file
async function parseCSV(path) {
  const response = await fetch(path);
  const text = await response.text();

  // 3. Split into lines, then split each line by comma
  const lines = text.split('\n');
  const rows  = lines.map(line => line.split(','));

  // 4. Filter: only keep rows from our year
  return rows.filter(row => row[3] === YEAR_FILTER);
}

async / await — downloading a file takes time. These keywords tell JavaScript "wait here until the download finishes before continuing." Without them, the code would try to draw bars before the data arrived!

4

Sorting Into Categories · Clasificando por Categorías

After loading, each row gets a category based on keywords in its Label column. This determines which color and position it gets in the 3D scene:

let category;
const label = row.label.toLowerCase();

if (label.includes('bilingual pcp')) {
  category = 'bilingual_pcp';
} else if (label.includes('limited english')) {
  category = 'limited_english';
} else if (label.includes('total')) {
  category = 'total';
} else {
  category = 'other';
}
💡

Want to add a new language? Add a new else if block with a keyword that appears in your data's Label column. We'll cover this more in later lessons!
¿Quieres agregar un nuevo idioma? Agrega un nuevo bloque else if.

5

Population → Bar Height · Población → Altura de la Barra

The most important step: turn a raw population number into a height that makes visual sense in 3D space.

// The tallest bar (Spanish Total: 87,798 people) gets MAX height
const MAX_POPULATION     = 87798;
const MAX_PEDESTAL_HEIGHT = 5.0;   // units in 3D space
const MIN_PEDESTAL_HEIGHT = 0.35;  // so tiny bars still show

// Scale: 87,798 people = 5.0 height units
//         1,000 people = 5.0 * (1000/87798) = 0.057 units
const height = MIN_PEDESTAL_HEIGHT +
  (population / MAX_POPULATION) *
  (MAX_PEDESTAL_HEIGHT - MIN_PEDESTAL_HEIGHT);

This is called linear scaling — the same math used in every chart you've ever seen, just applied to 3D height!

🛠 Try It · Inténtalo

Open docs/data/Equal_Access_Accommodations_20260410.csv in a text editor. Find the row for "Vietnamese" or another language. What's the population number? How tall do you think its bar should be compared to Spanish?

Abre el archivo CSV. Busca una fila para otro idioma. ¿Cuánta gente habla ese idioma en Oakland?

← Lesson 1 Lesson 3: Colors →