Histogram
Use it when an average hides what is happening. A median conversation may be four questions while a few run to sixty, and a histogram shows both. Pool the long tail into a last bar so the common cases stay readable, and mark the median and the 90th percentile.
How to use it
Paste the toolkit from Get the code into your page first, then call the chart like this.
const chart = histogram({
values: costPerResponse, // one number per response
min: 0,
max: quantile(costPerResponse, 0.97), // pool the long tail into an 'or more' bar
xfmt: v => '£' + (Math.round(v * 1000) / 1000),
xtitle: 'Cost of one answer',
unit: 'Responses',
markers: [
{ value: median(costPerResponse), label: 'Median £0.009' },
{ value: quantile(costPerResponse, 0.9), label: '90% are under £0.021' }
],
label: 'Cost per response',
empty: 'No responses in this range'
});
document.querySelector('#host').append(chart);Options
What you can pass to this chart.
values
Array of raw numbers. The chart bins them for you; use histBins(o) to get the same bins for a table.
min, max
Axis floor, and a ceiling: values at or above max pool into a final 'or more' bar.
binWidth, bins
A fixed bin width, or roughly how many bins you want (default about the square root of the count).
integer
True for whole-number data such as a count of questions: one bar per value, labels centred.
share
True to show each bar as a percentage of all values instead of a count.
markers
[{ value, label }]: dashed reference lines such as the median and the 90th percentile.
xfmt, yfmt, xtitle, unit
Formatters, the x-axis title and the noun used in the tooltip.
label / empty
aria-label for screen readers; text shown when there is no data.
More charts like this
Other charts in the “Spread and relationships” group.
Want charts or dashboards like these in your own product?
Tell me what you are trying to see and I can help work out the right approach, from the data behind it to the screen in front of people.