liveBook · Manning

D3.csv()

As explained in D3.js in Action, Third Edition

d3.csv() is a D3.js data-loading function that retrieves and parses comma-separated values into JavaScript data objects.

d3.csv() loads a comma-separated values file and turns its rows into JavaScript objects that can feed a D3 visualization. Pass the file path as the first argument; use the optional row-conversion callback to prepare each row before chart construction. section 3.1.3 section 3.2.1

Use d3.csv() as a small data-preparation workflow:

  • Point to the CSV file, such as d3.csv("../data/data.csv");. section 3.2.1
  • Recognize that the first line normally supplies column headers and each later line supplies a data row. section 3.1.3
  • Convert imported strings into the types your visualization needs; CSV count values commonly arrive as strings. section 3.2.2
  • Return only the key-value pairs needed later when using the row-conversion callback; omitted columns are unavailable after loading. section 3.2.2
  • Wait for asynchronous loading to finish before measuring, reorganizing, or binding the dataset to visual elements. section 3.6

Prepare survey counts for a chart

d3.csv("../data/data.csv", d => {\n return {\n technology: d.technology,\n count: +d.count\n };\n});\n\nThe callback receives one row at a time, keeps the technology and count fields, and converts count from text to a number. The resulting records are ready for later visualization work. section 3.2.2 section 3.2.1

Listing 3.1 Tools most used by data practitioners (data.csv)
technology,count
ArcGIS,147
D3.js,414
Angular,20
Datawrapper,171
Excel,1078
Flourish,198
ggplot2,435
Gephi,71
Google Data Studio,176
Highcharts,58
Illustrator,426
Java,29
Leaflet,134
Mapbox,167
kepler.gl,24
Observable,157
Plotly,223
Power BI,460
PowerPoint,681
Python,530
QGIS,193
Qlik,61
R,561
React,145
Tableau,852
Vega,48
Vue,51
Web Components,79
WebGL,65
Pen & paper,522
Physical materials,69
Canvas,121
P5/Processing,55

Inspect a complete CSV dataset whose technology and count columns demonstrate the tabular shape consumed by d3.csv(). section 3.2.1

How D3.js in Action, Third Edition covers it

How deep it goes
Explains paths, row callbacks, type conversion, column selection, and asynchronous timing, while deferring complete-dataset handling to then().
Examples
Uses a data-visualization-tools survey CSV containing technology names and practitioner counts.
What it assumes
Assumes basic JavaScript objects and functions while teaching CSV structure, D3 loading, and imported-value conversion.
What you can do after
Build it from scratch by loading a CSV, converting row values, and preparing records for a D3 visualization.
How it connects
Connects CSV loading with JSON, TSV, DSV, JavaScript Promises, data binding, and D3 visualization workflows.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.