-
Book Overview & Buying
-
Table Of Contents
Learn D3.js - Second Edition
By :
D3 comes with a separate module for tabular data parsers and formatters, which provides greater control over the parsing process. Tabular fetching functions also support additional arguments (up to four), which can be used to modify the data while it is parsed. We will cover these topics in this section.
A function can be provided as the last argument in d3.csv(), d3.tsv(), or d3.dsv() to modify the row object during parsing. This function receives two arguments: the row parsed as an object or array, and the row’s index, and should return a value, object, or array. You can use it to change, remove, or add properties for each row, or even to replace the row.
For example, the following code sums existing values to a new property called Total (see Tabular/1-d3-csv-function.html):
const data = await d3.csv(dataFile, row => {
row.Total = +row.Gold + +row.Silver + +row.Bronze;
...