liveBook · Manning

D3.max()

As explained in D3.js in Action, Third Edition

d3.max() is a D3-array function that returns the maximum value in an iterable, optionally by applying an accessor function.

d3.max() returns the largest value in an iterable. Pass the dataset first, then an accessor function that identifies the numeric property to compare. section 3.2.3

Use d3.max() while exploring data before building a chart:

  • Call d3.max(data, d => d.count) to compare each object's count value. section 3.2.3
  • Log the result to estimate the scale and bar lengths needed for a visualization. section 3.2.3
  • Use d3.min() for the smallest value or d3.extent() for both bounds. section 3.2.3

Measure technology counts

After loading the CSV and converting count to a number, run d3.max(data, d => d.count). For the 33-item technology dataset, the result is 1078; d3.min(data, d => d.count) returns 20.

How D3.js in Action, Third Edition covers it

How deep it goes
Defines the iterable and accessor parameters, demonstrates output, and stops short of implementation internals.
Examples
Uses a 33-item technology dataset whose count values range from 20 to 1078.
What it assumes
Assumes iterable data, object properties, arrow functions, and numeric CSV conversion.
What you can do after
Apply it via D3 to find a dataset maximum and estimate chart dimensions before rendering.
How it connects
Connects maximum measurement with data loading, accessors, d3.min(), d3.extent(), sorting, and bar charts.

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.