Skip to content
mbostock edited this page Jun 30, 2011 · 17 revisions

API ReferenceLayouts

# d3.layout.histogram()

Constructs a new histogram function with the default value accessor, range function, and bin function. By default, the histogram function returns frequencies.

# histogram(values[, index])

Evaluates the histogram function on the specified array of values. An optional index may be specified, which is passed along to the range and bin function.

# histogram.value([value])

Specifies how to extract a value from the associated data. The default value function is Number, which is equivalent to the identity function.

# histogram.range([range])

Specifies the range of the histogram. Values outside the specified range will be ignored. The argument x may be specified either as a two-element array representing the minimum and maximum value of the range, or as a function that returns the range given the array of values and the current index i. The default range is the extent (minimum and maximum) of the values.

# histogram.bins([bins])

Specifies how to bin values in the histogram. The argument x may be specified as a number, in which case the range of values will be split uniformly into the given number of bins. Or, x may be an array of threshold values, defining the bins; the specified array must contain the rightmost (upper) value, thus specifying n + 1 values for n bins. Or, x may be a function which is evaluated, being passed the range, the array of values, and the current index i, returning an array of thresholds. The default bin function will divide the values into uniform bins using Sturges' formula.

# histogram.frequency([frequency])

Specifies whether the histogram's y value is a count (frequency) or a probability (density). The default value is true.

Clone this wiki locally