Charts - Line & Area
Line charts for trends and comparisons. Supports area fills, stacking, range bands, and segment-level styling.
#Usage
import { ChartCanvas, ChartItem, ChartLine, ChartRange, ChartStacked, ChartSvg, ChartXAxis, ChartYAxis } from '@primeui/vue-chart';<ChartSvg>
<ChartLine :data="data" category-x-field="categoryXField" value-y-field="valueYField" />
<ChartXAxis />
<ChartYAxis />
</ChartSvg>Line charts track changes over time or across ordered categories. Data and styling live on ChartLine; axes frame the scale. Set fillOpacity to switch to area mode. Use ChartStacked to accumulate multiple series.
#Basic
A line chart connects data points to show trends over time or across categories. Set categoryXField and valueYField to bind data fields. Add ChartXAxis and ChartYAxis to render axes and gridlines.
#Area
Set fillOpacity to fill the region beneath the line. 0 draws only the line, 0.3 gives a semi-transparent fill. Any value above 0 activates area mode.
#Colors
Set color to apply a single color to the line and its area fill. Accepts any CSS color string.
#Gradient Color
Pass a linear gradient object to color to apply a gradient to the line stroke and area fill. Define direction with normalized coordinates (x1, y1 → x2, y2) and stops for color transitions. { x1: 0, y1: 0, x2: 0, y2: 1 } creates a top-to-bottom gradient. Line strokes default to horizontal; area fills default to vertical.
#Curve Types
Set curve to control how the line interpolates between points. linear draws straight segments. smooth uses monotone cubic interpolation that never overshoots. spline uses a Catmull-Rom spline with configurable tension for a looser curve. The step variants (step, step-before, step-after) draw discrete horizontal transitions, useful for state and threshold data.
#Null Handling
By default, null values break the line into separate segments ('gap'). Set connectNulls="connect" to bridge gaps with a straight segment. Set connectNulls="zero" to treat nulls as zero, which is only appropriate when zero is a meaningful value rather than missing data. true and false are aliases for 'connect' and 'gap'.
#Segment Styling
Set segmentColor, segmentStrokeWidth, segmentDash, or segmentFillColor to style individual line segments. Each prop accepts a static value or a callback receiving the two endpoints (p0 and p1) with their values and positions. Return undefined from a callback to fall back to the series default for that segment.
#Markers
Set showMarkers to display point markers at each data vertex. Use markerShape to differentiate series. Built-in shapes are circle, square, triangle, cross, and star. Set markerSize to control the radius and pointRotation to rotate the marker shape.
#Custom Markers
Set renderMarker to replace built-in markers with custom content. The callback receives the full PointRenderContext for each point. Use ctx.index or ctx.data to vary the marker per point. In SVG mode return a VNode centered at the origin; the chart handles translation to each point position. In Canvas mode the context is pre-translated to the point; draw at origin and return null.
#Line Styling
Set lineStrokeWidth to control stroke thickness. Use lineDash for dashed or dotted patterns with lineDashOffset to shift the pattern. Set lineCapStyle for line endings and lineJoinStyle for how segments connect at data points.
#Line Border
Set borderColor and borderStrokeWidth to draw a halo stroke behind the main line. The halo renders wider than the line itself, which keeps lines readable when they cross area fills or other series. Use borderDash for a dashed halo and borderCapStyle to control its line endings independently from the main stroke.
#Stacked Area
Wrap multiple ChartLine components inside ChartStacked to stack series vertically. Works with line-only and area series. Set mode="percent" on ChartStacked to normalize each category to 100%. Negative values stack downward from zero.
#Range Area
Wrap two ChartLine components inside ChartRange to fill the region between them. Set color on ChartRange for a uniform fill, or omit it for dual-color mode where each line's color fills the region where that series is on top. ChartRange requires exactly two ChartLine children. Fewer renders nothing; more than two uses only the first two.
#Declarative
Define data points inline using ChartItem children instead of a data array. Each ChartItem accepts category-x and value-y, or category-y and value-x for horizontal lines, and color.
#Title & Caption
Add ChartTitle to display a title above the chart and ChartCaption for a descriptive line beneath it. Adding both reduces the available chart area.
For full configuration see Title & Caption.
#Hover
ChartHover brightens the hovered point while the rest stay at normal opacity. Shared X-position hover is most useful when several series share the same ordered axis.
For full configuration see Hover.
#Tooltip
Add ChartTooltip to show data details on hover. Shared tooltips and crosshairs keep readers oriented across multiple series on the same ordered axis.
For full configuration see Tooltip.
#Legend
Add ChartLegend to display an interactive legend. Each ChartLine series appears as a separate entry; click any item to toggle that series.
For full configuration see Legend.
#Axes
Use label on ChartXAxis and ChartYAxis to add axis titles. Time axes suit continuous dates; use a secondary Y axis only when one scale would hide a series because the units differ.
For full configuration see Axes.
#Data Labels
Add ChartDataLabels to label data points. Line labels work best for endpoints, sparse checkpoints, or a few key events. Avoid labeling every vertex in dense time series.
For full configuration see Data Labels.
#Zoom & Navigator
Add ChartZoom and ChartNavigator when the ordered range is longer than the visible chart can explain at once.
For full configuration see Zoom & Pan and Navigator.
#Annotation
Use ChartAnnotation to render custom content overlaid on the chart area. Use for event markers, threshold callouts, or forecast boundaries tied to specific data coordinates.
For full configuration see Annotation.
#Reference Lines & Bands
Add ChartReferenceLine for threshold and divider lines. Add ChartReferenceBand to highlight tolerance, forecast, or alert ranges.
For full configuration see Reference Lines & Bands.
#Animation
Pass the chart-root animation prop to control entrance and update transitions. Keep animation for small updates; use Canvas rendering when point volume grows.
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
#ChartLine
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[] | - | Data array. Mutually exclusive with ChartItem children |
categoryXField | accessor → string | - | X-axis category field. Falls back to the array index when unset |
valueYField | accessor → number | 'value' | Y-axis numeric value field |
color | FillValue | default palette | Line stroke and area fill color (series-level). Accepts hex, RGB, and gradient objects. For per-point coloring use pointBackgroundColor / pointBorderColor |
name | string | - | Series name, used in legend and tooltip |
keyField | string | - | Field name for stable item identity. Used for animation matching when data is reordered. Not supported on stacked series, which animate by category position |
id | string | auto | Unique dataset identifier |
order | number | auto | Stacking order. 0 = bottom |
lineStrokeWidth | number | 2 | Line stroke thickness (px) |
lineCapStyle | 'butt' | 'round' | 'square' | 'round' | How the ends of line segments are drawn |
lineJoinStyle | 'round' | 'bevel' | 'miter' | 'round' | How path segments connect at data points |
lineDash | number[] | - | Dash pattern [dashLength, gapLength] |
lineDashOffset | number | - | Offset for the dash pattern |
lineStyle | 'solid' | 'dashed' | 'dotted' | 'solid' | Named shortcut for lineDash |
curve | 'linear' | 'smooth' | 'spline' | 'step' | 'step-before' | 'step-after' | 'linear' | Interpolation between data points |
tension | 0–1 | 0.5 | Spline tightness. Only applies when curve is 'spline'. 0 = straight lines, 0.5 = Catmull-Rom |
fillOpacity | 0–1 | 0 | Area fill opacity beneath the line. 0 = line only |
borderColor | accessor → FillValue | - | Line halo stroke color drawn behind the main stroke (e.g. for outlines/shadows) |
borderStrokeWidth | accessor → number | - | Halo stroke width |
borderDash | accessor → number[] | - | Halo dash pattern. Also accepts named shortcuts ('solid', 'dashed', 'dotted') |
borderDashOffset | accessor → number | 0 | Halo dash phase offset |
borderCapStyle | 'butt' | 'round' | 'square' | 'round' | Halo line cap style |
showMarkers | boolean | false | Display point markers at each data vertex |
markerSize | accessor → number | 4 | Marker radius (px). Per-point via array/callback |
markerShape | accessor → string | 'circle' | Built-in enum ('circle' | 'square' | 'triangle' | 'cross' | 'star') or any custom SVG path d string. Per-item callback receives ItemContext<T> & { size: number } |
pointRotation | accessor → number | 0 | Marker rotation in degrees (0 = upright). Per-point via array/callback |
pointBackgroundColor | accessor → FillValue | series color | Marker fill color. Per-point via array/callback |
pointBorderColor | accessor → FillValue | - | Marker border stroke color |
pointBorderStrokeWidth | accessor → number | - | Marker border stroke width (px) |
pointBorderDash | accessor → number[] | - | Marker border dash pattern |
pointBorderDashOffset | accessor → number | 0 | Marker border dash phase offset |
pointBorderJoinStyle | 'round' | 'bevel' | 'miter' | 'miter' | Marker border path join style |
pointHitRadius | number | 10 | Invisible hover detection radius around each point |
hoverPointRadius | number | markerSize × 1.3 | Marker radius when hovered (px) |
pointHoverBackgroundColor | FillValue | - | Marker fill color on hover |
pointHoverBorderColor | FillValue | - | Marker border color on hover |
pointHoverBorderStrokeWidth | number | - | Marker border width on hover (px) |
connectNulls | boolean | 'gap' | 'connect' | 'zero' | 'gap' | Null value handling. false/'gap' = path break (default), true/'connect' = bridge over nulls, 'zero' = treat as zero. Only use when zero is a meaningful baseline |
segmentColor | FillValue | (ctx: SegmentContext<T>) => string | undefined | - | Per-segment stroke color. Return undefined from the callback to use the series default |
segmentStrokeWidth | number | (ctx: SegmentContext<T>) => number | undefined | - | Per-segment stroke width |
segmentDash | number[] | (ctx: SegmentContext<T>) => number[] | undefined | - | Per-segment dash pattern |
segmentFillColor | FillValue | (ctx: SegmentContext<T>) => string | undefined | - | Per-segment area fill color. Area mode only |
renderMarker | (context: PointRenderContext) => unknown | - | Custom marker renderer. SVG: return a VNode centered at origin. Canvas: draw to ctx and return null |
xAxisId | string | - | Bind to a specific X-axis by ID |
yAxisId | string | - | Bind to a specific Y-axis by ID |
#ItemContext
Passed to every accessor → R callback. Return undefined to fall back to the series-level default for that item.
| Field | Type | Description |
|---|---|---|
datum | T | Original data row |
value | number | null | Resolved numeric value (when applicable) |
index | number | Position within the dataset |
seriesIndex | number | Order of this series within the chart |
seriesId | string | Dataset id |
category | string? | Resolved category label, when applicable |
size | number? | Current marker pixel size, populated for marker accessors |
#SegmentContext
Passed to per-segment callbacks (segmentColor, segmentStrokeWidth, segmentDash, segmentFillColor).
| Field | Type | Description |
|---|---|---|
p0 | ComputedPoint | Start point of the segment |
p1 | ComputedPoint | End point of the segment |
p0DataIndex | number | Data index of the start point |
p1DataIndex | number | Data index of the end point |
datum0 | T? | Underlying datum at p0DataIndex (when data passed) |
datum1 | T? | Underlying datum at p1DataIndex (when data passed) |
seriesId | string? | Series id this segment belongs to |
seriesIndex | number? | Series order index |
#ComputedPoint
| Field | Type | Description |
|---|---|---|
x | number | Pixel X coordinate |
y | number | Pixel Y coordinate |
value | number | null | Raw data value. null for gap points |
category | string | Category label |
dataIndex | number | Original data index |
#ChartStacked
Wrap ChartLine children inside ChartStacked to stack series vertically. Works with both line-only and area series. Without this wrapper, multiple ChartLine components overlap each other.
| Prop | Type | Default | Description |
|---|---|---|---|
mode | 'normal' | 'percent' | 'normal' | normal = absolute values stacked (negative values naturally stack downward). percent = normalized to 100% |
gap | number | 0 | Pixel gap between stacked series |
id | string | auto | Stack group identifier |
#ChartRange
Wrap exactly two ChartLine components inside ChartRange to fill the area between them. Fewer than two children renders nothing, more than two uses only the first two.
| Prop | Type | Default | Description |
|---|---|---|---|
color | FillValue | - | Single fill color for the range area. Omit for dual-color mode. Each child's line color fills the region where that series is on top |
fillOpacity | 0–1 | 0.3 | Fill opacity for the range area |
id | string | auto | Range group identifier |
#ChartItem
Use ChartItem as children of ChartLine instead of a data array for inline data definitions.
| Prop | Type | Description |
|---|---|---|
category-x | string | X-axis category |
value-y | number | Y-axis value |
category-y | string | Y-axis category |
value-x | number | X-axis value |
color | string | Override color for this point |
#PointRenderContext
Passed to the renderMarker callback for each data point.
| Field | Type | Description |
|---|---|---|
x | number | Pixel X coordinate of the point |
y | number | Pixel Y coordinate of the point |
index | number | Data index |
value | number | null | Raw data value |
category | string | Category label |
data | T | Original data item from the data array |
color | string | Resolved series color |
size | number | Current marker radius in pixels. Larger when hovered |
isHovered | boolean | Whether this point is currently hovered |
opacity | number | Computed opacity from hover dim effects (0–1). Apply to the custom marker to respect dimOpacity |
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. Handles loading and caching. Canvas mode only |
animate | function | undefined | Register a continuous animation on a numeric property. Drives the canvas RAF loop while active. Canvas mode only |