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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#Gradient Color

color also accepts a gradient definition. Linear and radial gradients both work, in SVG and Canvas.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#Title & Caption

Add ChartTitle and ChartCaption for a heading and a source note.

Loading Demo...

#Hover

Add ChartHover to enable hover styling. hoverColor sets a per-bin fill that short-circuits the global brightness cascade.

Loading Demo...

#Tooltip

ChartTooltip reports the bin range alongside the bar value, so the boundaries of each range stay visible.

Loading Demo...

#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.

Loading Demo...

#Axes

Bind yAxisId to put series on separate value axes. The independent axis stays continuous, since bins are ranges rather than categories.

Loading Demo...

#Data Labels

ChartDataLabels draws the reduced value on each bin.

Loading Demo...

#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.

Loading Demo...

#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.

Loading Demo...

#Reference Lines & Bands

ChartReferenceLine marks a threshold on either axis, which suits service levels and distribution targets.

Loading Demo...

#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.

PropTypeDefaultDescription
dataT[]-Array of raw observations. Mutually exclusive with ChartItem children
binXFieldaccessor → number-Observations to bin along X, making the histogram vertical
binYFieldaccessor → 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
binWidthnumber-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
valueYFieldaccessor → number-Measure reduced into each bar's height, for a vertical histogram
valueXFieldaccessor → number-Measure reduced into each bar's length, for a horizontal histogram
coloraccessor → FillValuedefault paletteBar fill color. Static color, per-bin array (cycles by index), or callback
opacityaccessor → number1Bar fill opacity in [0, 1]. Softened automatically for overlaid series
namestring-Series name, used in legend and tooltip
keyFieldstring-Field name giving each item a stable identity when data is reordered. Values must be unique, or the series falls back to positional matching.
idstringautoUnique dataset identifier
barThicknessnumber-Fixed bar thickness in pixels. Overrides the bin's own width, so it misreports unequal bins
maxBarThicknessnumber-Caps the bin's own width in pixels. Ignored when barThickness is set
minBarLengthnumber-Minimum bar length in pixels, so low-count bins stay visible
barGap0–10.02Gap between series within one bin. Only applies to grouped histograms
categoryGap0–1-Gap between bins as a ratio of the bin width. Unset leaves a 1px separation
borderRadiusaccessor → BorderRadius0Corner radius. Number, { topLeft, topRight, bottomLeft, bottomRight }, array, or callback
borderStrokeWidthaccessor → number-Border stroke width in pixels
borderColoraccessor → FillValue-Border stroke color
borderDashaccessor → number[]-Dash pattern [dashLength, gapLength], or a named shortcut
borderDashOffsetaccessor → number0Offset 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
borderSkippedaccessor → (false | 'start' | 'end' | 'top' | 'bottom' | 'left' | 'right')-Which bin edge(s) skip the border stroke. Orientation-aware: 'start' is always the baseline edge
hoverColoraccessor → FillValue-Per-bin fill color on hover. Short-circuits the global ChartHover.brightness cascade
hoverBorderColoraccessor → 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
xAxisIdstring-Bind to a specific X-axis by ID
yAxisIdstring-Bind to a specific Y-axis by ID
ordernumberautoStacking order within ChartStacked. 0 is the bottom of the stack
stackIdstring-Stack group identifier
animationsRecord<string, NamedAnimationSpec>-Per-dataset property animations

#Bin

The datum passed to every accessor callback is a bin rather than an original row.

FieldTypeDescription
x0numberLower bound of the range, inclusive
x1numberUpper bound of the range, exclusive except in the final bin
countnumberNumber of observations in the range
valuenumberReduced 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.

PropTypeDescription
bin-xnumberOne observation binned along X, making the histogram vertical
bin-ynumberOne observation binned along Y, making the histogram horizontal
value-ynumberMeasure reduced into the bar height, for a vertical histogram
value-xnumberMeasure reduced into the bar length, for a horizontal histogram
colorstringOverride 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.