Charts - Data Labels

Display values directly on chart elements with full control over content, formatting, leader lines, and custom rendering.

#Usage

import { ChartDataLabels, ChartSvg } from '@primeui/vue-chart';
<ChartSvg>
    <!-- series and axes -->
    <ChartDataLabels />
</ChartSvg>

Data labels are opt-in: add ChartDataLabels to display values on chart elements; remove it and labels disappear. Works across all chart types. Use display, format, and render to control content; color, fontSize, and offset to control appearance.

#Basic

Add ChartDataLabels to display values on chart elements. By default labels show the raw value at each data point, bar, or slice.

Loading Demo...

#Display Mode

Set display to control what is shown. value shows the raw number, percentage shows the proportion of the total, and both shows both. Set display="none" to hide labels without removing the component.

Loading Demo...

#Formatter

Set formatter to control the label text. The callback receives the raw value, the percentage (0–100), the category label, and the row datum, and returns a string. Use the datum to pull sibling fields into the label. Use this for currency formatting, units, and conditional display logic.

Loading Demo...
Security. formatter returns a string, rendered as text (textContent) and never parsed as HTML. There is no XSS surface even with untrusted data: any returned markup shows up as literal text, not elements.

#Min Percentage

Set minPercentage to hide labels on slices or segments smaller than a threshold. Applies to pie, donut, polar, and radar charts.

Loading Demo...

#Leader Lines

On pie and donut charts, labels render outside the slices with a leader line connecting each label to its slice. Set lineStyle to angled (default; radial segment with horizontal elbow), straight (single direct line), or none (no connector). Set alignTo to labelLine (labels align to the line end) or edge (labels align flush to the chart boundary).

Loading Demo...

#Align To

Set alignTo to edge to align all outside labels flush to the chart boundary. Labels on both sides line up at the same horizontal distance, giving a column layout. The default labelLine positions each label at its own leader line end.

Loading Demo...

#Styling

Set fontSize to adjust label text size. Set color to override the default label color. Pass a string for uniform color or an array for per-item colors. Use lineHeight to adjust the line height multiplier when labels wrap.

Loading Demo...

#Offsets

Use distance (alias: leaderOffset) to control the gap between the slice edge and the start of the leader line on circular charts. Use textGap (alias: textOffset) to add space between the leader line end and the label text. Use horizontalOffset to shift labels horizontally after alignment.

Loading Demo...

#Custom Label

Set render to replace the default label with custom content. The callback receives the full DataLabelContext. Use formattedText for the pre-formatted value, x/y for position, and ctx in Canvas mode to draw imperatively.

Loading Demo...

#API

#ChartDataLabels

fontSize and color are layout-aware per-label accessors. When an array, callback, or field name is provided, the per-label font size is honored during collision detection and layout. For combo charts, branch on seriesId inside the callback to vary styling per series.

Universal props (apply to all chart types):

PropTypeDefaultDescription
display'value' | 'percentage' | 'both' | 'none' | 'label' | 'label-percentage''value'What to display in each label
formatter(value: number, percentage?: number, label?: string, datum?: T) => string-Custom label text. Overrides display. Receives value, percentage (0–100), category label, and the row datum
fontSizeaccessor → numberthemeLabel font size in pixels. Per-label via array, callback (ctx) => number, or keyof T
fontFamilystringthemeLabel font family
fontWeight'normal' | 'bold' | number'normal'Label font weight
coloraccessor → FillValueauto-contrastLabel text color. Per-label via array, callback (ctx) => FillValue, or keyof T
lineHeightnumber1.2Line height multiplier
render(context: DataLabelContext) => unknown-Custom label renderer. Replaces the default layout entirely

Pie and donut only (ignored on bar, line, scatter, and other chart types):

PropTypeDefaultDescription
minPercentagenumber5Hide labels on slices or segments smaller than this percentage. Pie, donut, polar, and radar
lineStyle'angled' | 'straight' | 'none''angled'Leader line style for outside labels
alignTo'labelLine' | 'edge''labelLine'Outside label alignment. labelLine positions at line end, edge aligns flush to chart boundary
distancenumber10Gap between slice edge and leader line start. Alias: leaderOffset
textGapnumber4Gap between leader line end and label text. Alias: textOffset
horizontalOffsetnumber15Horizontal distance from leader line elbow to text anchor
connectorColoraccessor → FillValueslice colorOutside-label connector stroke color. Per-slice via array, callback (ctx) => FillValue, or keyof T
connectorWidthaccessor → number1Outside-label connector stroke width (px). Per-slice via array, callback (ctx) => number, or keyof T

#DataLabelContext

Passed to the render callback for each label.

FieldTypeDescription
indexnumberData item index
valuenumberRaw numeric value
datumT | undefinedRaw data row for this label. Undefined when the source data is unavailable
percentagenumberPercentage of total (0–100)
formattedTextstringPre-formatted label text from formatter or display mode. Use this for display
labelstringCategory or slice label
colorstringResolved label color
xnumberLabel X position in pixels
ynumberLabel Y position in pixels
side'left' | 'right' | undefinedWhich side of the chart the label is on. Outside circular labels only
leaderLine{ x1, y1, x2, y2, x3, y3 } | undefinedLeader line geometry in absolute coordinates. Pie and donut outside labels only
center{ x: number; y: number } | undefinedChart center point. Pie and donut only
ctxCanvasRenderingContext2D | undefinedCanvas context. Present only in Canvas mode
drawImagefunction | undefinedDraw an image from a URL at a position relative to origin. Canvas mode only