Histogram
How readings are spread: bins between round numbers, each as tall as its count.
On this page
A histogram shows how readings are spread: where most of them lie, how far they reach, whether they lean to one side. The readings of the first series are sorted into bins between round numbers, and each bin is a bar as tall as the count of readings in it. The bins touch, since the scale under them runs on without a break.
Histogram
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure></div><script>addEventListener('DOMContentLoaded', function () {var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })MasterUI.chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach, chart } from '@master/ui/behaviors'var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => { const detach = [ attach(root.current!), chart(document.getElementById('spread')!, { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ] return () => detach.forEach(stop => stop()) }, []) return ( <div ref={root} className="card max-w(560) mx-auto"> <div className="card-header"> <h3 className="card-title">Response time</h3> <p className="card-description">240 requests, in milliseconds</p> </div> <figure className="chart" id="spread"></figure> </div> )}<script> import { attach, chart } from '@master/ui/behaviors' var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) }) function mounted(root) { const detach = [ attach(root), chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ] return () => detach.forEach(stop => stop()) }</script><div class="card max-w(560) mx-auto" {@attach mounted}> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, chart } from '@master/ui/behaviors'var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })const root = ref(null)let detach = []onMounted(() => { detach = [ attach(root.value), chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template> <div ref="root" class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure> </div></template>Give the raw readings as the series' values, not counts: the chart counts them. bins asks for about that many bins; left out, their number follows the count of readings, between five and twenty. The edges are round numbers, so a bin reads as "200 to 250". A reading on an edge belongs to the bin that begins there.
A histogram is not a bar chart of names: its bars are ranges of one measure, in order. Amounts by name are bars, and five figures that sum a spread up are a box plot.
#Options
| Option | Default | |
|---|---|---|
label | none | What the chart shows and in what unit: the plot's accessible name |
series | [] | Each with a name and what its form reads: values, a value, points, ranges or children; optionally a category, a type, low and high, and a ring's max |
bins | from the count | About how many bins a histogram sorts its readings into |
min, max, ticks | fit, 4 | The ends of the scale and about how many steps mark it; xMin, xMax and xTicks for a scatter's scale across |
format, tickFormat | the locale's | How a value and a tick are written; xFormat for a scatter's scale across |
current | none | The index of the point marked aria-current |
The readout, the keys, the legend, the colors and the scale are the same in every form: Chart holds them, with every option, class and custom property.