Skip to content
kerfjsGitHub

Histogram

Sorts raw numbers into bins, to show how they are spread.

SourcePackage @kerf-js/veneer

Preview

tsx
import { Histogram } from '@kerf-js/veneer'export function Latency() {  return (  <Histogram    title="Storefront latency"    description="240 requests, last hour"    data={LATENCIES}    binWidth={20}    format={ms}    name="Requests"  />  )}const wobble = (i: number) =>  (Math.sin(i * 12.9898) * 43758.5453) % 1const LATENCIES = Array.from(  { length: 240 },  (_, i) =>    Math.round(      62 +        Math.abs(wobble(i)) * 70 +        Math.abs(wobble(i + 300)) * 50 +        (i % 37 === 0 ? 160 : 0),    ),)const ms = (v: number) => `${Math.round(v)} ms`

Installation

npm install @kerf-js/veneer

Usage

tsx
import { Histogram } from '@kerf-js/veneer'<Histogram  title="Storefront latency"  description="240 requests, last hour"  data={LATENCIES}  binWidth={20}  format={ms}  name="Requests"/>

Accessibility

  • Every chart has a text alternative and a table view of its numbers, so nothing depends on seeing the marks. See Chart for its keyboard support.

API Reference

PropTypeDefaultDescription
titlestring—The heading.
level2 | 3 | 4 | 6 | 5—The title's heading level: one below the heading the chart sits under. Default 3, a chart in a page section.
descriptionunknown—One supporting line under the title.
toolbarunknown—Beside the view toggle: a layout switch, a range picker.
state"error" | "loading" | "empty"—Replaces the plot, in the same frame. With no data the frame shows empty on its own.
loadingstring—Shows that work is under way.
empty{ title: string; detail?: unknown; }—The title and detail shown in place of the plot when there is no data.
error{ title: string; detail?: unknown; }—A message that marks the field invalid and says why.
actionunknown—The next step under an empty or error state: a Retry button.
datanumber[]—The series to draw.
summarystring | ((c: { data: number[]; title: string; }) => string)—One sentence for screen readers and the page; generated from the data when absent.
binWidthnumber—The width of each bin, in the data's units.
formatFmt—Turns a value into the text shown.
namestring—What is being counted.

RelatedBox plot