Charts - Histogram
Distribution charts that bin raw observations into ranges and draw one bar per bin.
#Usage
import {
ChartAnnotation,
ChartCanvas,
ChartCaption,
ChartDataLabels,
ChartHistogram,
ChartHover,
ChartItem,
ChartLegend,
ChartNavigator,
ChartOverlap,
ChartReferenceLine,
ChartStacked,
ChartSvg,
ChartTitle,
ChartTooltip,
ChartXAxis,
ChartYAxis,
ChartZoom
} from '@primeui/vue-chart';<ChartSvg>
<!-- or <ChartCanvas> -->
<ChartHistogram :data="data" bin-x-field="binXField" :bins="10" />
<ChartXAxis />
<ChartYAxis />
</ChartSvg>A histogram takes raw observations rather than aggregated rows and groups them into bins, drawing one bar per bin. Each bar spans a range on the independent axis, so bar width carries data rather than presentation. Binning happens before layout, which means the rest of the cartesian pipeline treats the result as bars: axes, tooltips, legends, zoom, and annotations all behave as they do for ChartBar.
#Basic
Bind raw observations with binXField and nothing else. The bins are derived with the square-root rule, and each bar counts the observations whose value falls in its range.
#Bin Rules
bins takes a number to set the count outright, or a named rule that derives it from the number of observations: 'square-root' (the default), 'sturges', or 'rice'. A rule keeps the count proportionate as the data grows, where a fixed number does not.
#Explicit Edges
Pass an array of N+1 boundaries to control every bin. Ranges do not need equal width, and each bar is drawn at the width of its own range, so an unequal set stays truthful.
#Bin Width
binWidth sets the range of each bin in data units and takes precedence over bins. The final bin extends past the largest observation when the span does not divide evenly.
#Reduce
By default each bar is a count of its members. Bind a measure with valueYField and set reduce to 'sum', 'mean', 'min', or 'max' to aggregate that measure instead.
#Negative Values
A reduced measure can resolve below zero, and those bars extend downward from the baseline. Counting never produces a negative bar, so this applies only when reduce aggregates a signed measure.
#Colors
Pass an array to color for a custom palette. Bars cycle through the colors by bin index. A function receives each bin and returns a color string for per-bin control.
#Gradient Color
color also accepts a gradient definition. Linear and radial gradients both work, in SVG and Canvas.
#Grouped
Multiple ChartHistogram components render side by side within each bin. Bin edges are pooled across every series, so the bars line up and stay comparable.
#Stacked
Wrap the series in ChartStacked to stack bins on top of each other. Edges are pooled here as well, since stacking needs a shared base.
#Overlap
Wrap the series in ChartOverlap to layer distributions at the same position. Each series keeps its own bins unless the same bins value is passed to both, and overlaid fills are softened so the layers remain readable. Bars are not narrowed here, because a histogram's width is its bin.
#Horizontal
Bind binYField instead of binXField to run the bins down the Y axis. The measure then lands on X. There is no orientation prop.
#Custom Shape
renderShape replaces the default rectangle. It receives the computed geometry and returns an SVG path d string, which works in both SVG and Canvas.
#Border
Border props match ChartBar. Bins sit 1px apart by default, so a border outlines each range rather than fusing the series into one silhouette.
#Bin Sizing
categoryGap widens the gap between bins beyond the 1px default, and maxBarThickness caps how wide a bar may become. Both are presentation props: barThickness and maxBarThickness override the bin's own width, which misreports unequal bins.
#Declarative
Use ChartItem children instead of a data array. Each item is one observation bound with binX or binY, not one bar. This suits small or illustrative sets; a data array is better for large ones.
#Title & Caption
Add ChartTitle and ChartCaption for a heading and a source note.
#Hover
Add ChartHover to enable hover styling. hoverColor sets a per-bin fill that short-circuits the global brightness cascade.
#Tooltip
ChartTooltip reports the bin range alongside the bar value, so the boundaries of each range stay visible.
#Legend
ChartLegend lists each series by name. Toggling a series rescales the axis while the pooled bin edges stay fixed, so the remaining bars keep their position.
#Axes
Bind yAxisId to put series on separate value axes. The independent axis stays continuous, since bins are ranges rather than categories.
#Data Labels
ChartDataLabels draws the reduced value on each bin.
#Zoom & Navigator
ChartZoom and ChartNavigator work on the binned axis. Bins are derived once from the full dataset, so zooming moves the viewport rather than re-binning.
#Annotation
ChartAnnotation draws custom content over the plot area. The SVG renderer takes a template, and the Canvas renderer takes a render callback that receives the drawing context.
#Reference Lines & Bands
ChartReferenceLine marks a threshold on either axis, which suits service levels and distribution targets.
#Null Values
Observations that are not finite numbers are dropped before binning, including null, undefined, and NaN. No bin is created for them and no gap appears in the axis, since a histogram has no slot reserved per row. Counts therefore reflect the finite observations only. There is no connectNulls prop, because there is no category slot to preserve.
#Decimation
ChartDecimation does not apply to histograms. A histogram's rows are its bins, so dropping rows would discard whole ranges and lose the observations they hold. Bins are capped by the bins or binWidth props instead.
#Animation
Pass the chart-root animation prop to control entrance and update transitions. Bins keep their identity across updates while the edges stay fixed, so bars grow in place rather than snapping.
For full configuration see Animation.
#Export
Add ChartExportMenu to let users download the chart as PNG, SVG, or PDF.
See Export for format options and programmatic export.
#Responsive
See Responsive for container sizing, aspect ratio, and breakpoint configuration.
#Accessibility
See Accessibility for ARIA labels, keyboard navigation, and screen reader support.
#API
#ChartHistogram
Visual styling props with type accessor → R accept a static value, a per-item array, a field name (keyof T), or a callback (ctx: ItemContext<T>) => R | undefined. Color-family arrays cycle modulo length; other accessor arrays clip and fall back to the series default.
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | - | Array of raw observations. Mutually exclusive with ChartItem children |
binXField | accessor → number | - | Observations to bin along X, making the histogram vertical |
binYField | accessor → number | - | Observations to bin along Y, making the histogram horizontal |
bins | 'square-root' | 'sturges' | 'rice' | number | number[] | (values) => number | 'square-root' | How to subdivide. An array is N+1 edges giving N bins, which may be unequal |
binWidth | number | - | Exact bin width in data units. Takes precedence over bins |
reduce | 'count' | 'sum' | 'mean' | 'min' | 'max' | 'count' | How to reduce each bin's members. Anything other than 'count' needs a measure bound |
valueYField | accessor → number | - | Measure reduced into each bar's height, for a vertical histogram |
valueXField | accessor → number | - | Measure reduced into each bar's length, for a horizontal histogram |
color | accessor → FillValue | default palette | Bar fill color. Static color, per-bin array (cycles by index), or callback |
opacity | accessor → number | 1 | Bar fill opacity in [0, 1]. Softened automatically for overlaid series |
name | string | - | Series name, used in legend and tooltip |
keyField | string | - | Field name giving each item a stable identity when data is reordered. Values must be unique, or the series falls back to positional matching. |
id | string | auto | Unique dataset identifier |
barThickness | number | - | Fixed bar thickness in pixels. Overrides the bin's own width, so it misreports unequal bins |
maxBarThickness | number | - | Caps the bin's own width in pixels. Ignored when barThickness is set |
minBarLength | number | - | Minimum bar length in pixels, so low-count bins stay visible |
barGap | 0–1 | 0.02 | Gap between series within one bin. Only applies to grouped histograms |
categoryGap | 0–1 | - | Gap between bins as a ratio of the bin width. Unset leaves a 1px separation |
borderRadius | accessor → BorderRadius | 0 | Corner radius. Number, { topLeft, topRight, bottomLeft, bottomRight }, array, or callback |
borderStrokeWidth | accessor → number | - | Border stroke width in pixels |
borderColor | accessor → FillValue | - | Border stroke color |
borderDash | accessor → number[] | - | Dash pattern [dashLength, gapLength], or a named shortcut |
borderDashOffset | accessor → number | 0 | Offset for the dash pattern |
borderJoinStyle | 'round' | 'bevel' | 'miter' | 'miter' | How border segments connect at corners |
borderAlign | 'center' | 'inner' | 'center' | Border alignment relative to the bar edge |
borderSkipped | accessor → (false | 'start' | 'end' | 'top' | 'bottom' | 'left' | 'right') | - | Which bin edge(s) skip the border stroke. Orientation-aware: 'start' is always the baseline edge |
hoverColor | accessor → FillValue | - | Per-bin fill color on hover. Short-circuits the global ChartHover.brightness cascade |
hoverBorderColor | accessor → FillValue | - | Per-bin border color on hover |
renderShape | (bar: BarShapeInfo) => string | - | Custom shape per bin. Receives computed geometry, returns an SVG path d string. Works in SVG and Canvas |
xAxisId | string | - | Bind to a specific X-axis by ID |
yAxisId | string | - | Bind to a specific Y-axis by ID |
order | number | auto | Stacking order within ChartStacked. 0 is the bottom of the stack |
stackId | string | - | Stack group identifier |
animations | Record<string, NamedAnimationSpec> | - | Per-dataset property animations |
#Bin
The datum passed to every accessor callback is a bin rather than an original row.
| Field | Type | Description |
|---|---|---|
x0 | number | Lower bound of the range, inclusive |
x1 | number | Upper bound of the range, exclusive except in the final bin |
count | number | Number of observations in the range |
value | number | Reduced height. Equal to count unless reduce is set |
#ChartItem
Use ChartItem as children of ChartHistogram instead of a data array. Each item is one observation.
| Prop | Type | Description |
|---|---|---|
bin-x | number | One observation binned along X, making the histogram vertical |
bin-y | number | One observation binned along Y, making the histogram horizontal |
value-y | number | Measure reduced into the bar height, for a vertical histogram |
value-x | number | Measure reduced into the bar length, for a horizontal histogram |
color | string | Override color for the bin this observation falls into |
#ChartStacked
Wrap ChartHistogram children inside ChartStacked to stack bins. Without this wrapper, multiple histograms render as grouped side-by-side bars.
#ChartOverlap
Wrap multiple ChartHistogram components inside ChartOverlap to layer them at the same position. No configuration required. Each series keeps its own bins by default; passing the same bins value to every series makes them comparable.