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.
#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.
#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.
Security.formatterreturns 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.
#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).
#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.
#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.
#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.
#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.
#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):
| Prop | Type | Default | Description |
|---|---|---|---|
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 |
fontSize | accessor → number | theme | Label font size in pixels. Per-label via array, callback (ctx) => number, or keyof T |
fontFamily | string | theme | Label font family |
fontWeight | 'normal' | 'bold' | number | 'normal' | Label font weight |
color | accessor → FillValue | auto-contrast | Label text color. Per-label via array, callback (ctx) => FillValue, or keyof T |
lineHeight | number | 1.2 | Line 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):
| Prop | Type | Default | Description |
|---|---|---|---|
minPercentage | number | 5 | Hide 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 |
distance | number | 10 | Gap between slice edge and leader line start. Alias: leaderOffset |
textGap | number | 4 | Gap between leader line end and label text. Alias: textOffset |
horizontalOffset | number | 15 | Horizontal distance from leader line elbow to text anchor |
connectorColor | accessor → FillValue | slice color | Outside-label connector stroke color. Per-slice via array, callback (ctx) => FillValue, or keyof T |
connectorWidth | accessor → number | 1 | Outside-label connector stroke width (px). Per-slice via array, callback (ctx) => number, or keyof T |
#DataLabelContext
Passed to the render callback for each label.
| Field | Type | Description |
|---|---|---|
index | number | Data item index |
value | number | Raw numeric value |
datum | T | undefined | Raw data row for this label. Undefined when the source data is unavailable |
percentage | number | Percentage of total (0–100) |
formattedText | string | Pre-formatted label text from formatter or display mode. Use this for display |
label | string | Category or slice label |
color | string | Resolved label color |
x | number | Label X position in pixels |
y | number | Label Y position in pixels |
side | 'left' | 'right' | undefined | Which side of the chart the label is on. Outside circular labels only |
leaderLine | { x1, y1, x2, y2, x3, y3 } | undefined | Leader line geometry in absolute coordinates. Pie and donut outside labels only |
center | { x: number; y: number } | undefined | Chart center point. Pie and donut only |
ctx | CanvasRenderingContext2D | undefined | Canvas context. Present only in Canvas mode |
drawImage | function | undefined | Draw an image from a URL at a position relative to origin. Canvas mode only |