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.

Loading Demo...

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

Loading Demo...

#Colors

Set color to apply a single color to the line and its area fill. Accepts any CSS color string.

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

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.

Loading Demo...

For full configuration see Annotation.

#Reference Lines & Bands

Add ChartReferenceLine for threshold and divider lines. Add ChartReferenceBand to highlight tolerance, forecast, or alert ranges.

Loading Demo...

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.

PropTypeDefaultDescription
dataT[]-Data array. Mutually exclusive with ChartItem children
categoryXFieldaccessor → string-X-axis category field. Falls back to the array index when unset
valueYFieldaccessor → number'value'Y-axis numeric value field
colorFillValuedefault paletteLine stroke and area fill color (series-level). Accepts hex, RGB, and gradient objects. For per-point coloring use pointBackgroundColor / pointBorderColor
namestring-Series name, used in legend and tooltip
keyFieldstring-Field name for stable item identity. Used for animation matching when data is reordered. Not supported on stacked series, which animate by category position
idstringautoUnique dataset identifier
ordernumberautoStacking order. 0 = bottom
lineStrokeWidthnumber2Line 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
lineDashnumber[]-Dash pattern [dashLength, gapLength]
lineDashOffsetnumber-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
tension0–10.5Spline tightness. Only applies when curve is 'spline'. 0 = straight lines, 0.5 = Catmull-Rom
fillOpacity0–10Area fill opacity beneath the line. 0 = line only
borderColoraccessor → FillValue-Line halo stroke color drawn behind the main stroke (e.g. for outlines/shadows)
borderStrokeWidthaccessor → number-Halo stroke width
borderDashaccessor → number[]-Halo dash pattern. Also accepts named shortcuts ('solid', 'dashed', 'dotted')
borderDashOffsetaccessor → number0Halo dash phase offset
borderCapStyle'butt' | 'round' | 'square''round'Halo line cap style
showMarkersbooleanfalseDisplay point markers at each data vertex
markerSizeaccessor → number4Marker radius (px). Per-point via array/callback
markerShapeaccessor → 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 }
pointRotationaccessor → number0Marker rotation in degrees (0 = upright). Per-point via array/callback
pointBackgroundColoraccessor → FillValueseries colorMarker fill color. Per-point via array/callback
pointBorderColoraccessor → FillValue-Marker border stroke color
pointBorderStrokeWidthaccessor → number-Marker border stroke width (px)
pointBorderDashaccessor → number[]-Marker border dash pattern
pointBorderDashOffsetaccessor → number0Marker border dash phase offset
pointBorderJoinStyle'round' | 'bevel' | 'miter''miter'Marker border path join style
pointHitRadiusnumber10Invisible hover detection radius around each point
hoverPointRadiusnumbermarkerSize × 1.3Marker radius when hovered (px)
pointHoverBackgroundColorFillValue-Marker fill color on hover
pointHoverBorderColorFillValue-Marker border color on hover
pointHoverBorderStrokeWidthnumber-Marker border width on hover (px)
connectNullsboolean | '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
segmentColorFillValue | (ctx: SegmentContext<T>) => string | undefined-Per-segment stroke color. Return undefined from the callback to use the series default
segmentStrokeWidthnumber | (ctx: SegmentContext<T>) => number | undefined-Per-segment stroke width
segmentDashnumber[] | (ctx: SegmentContext<T>) => number[] | undefined-Per-segment dash pattern
segmentFillColorFillValue | (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
xAxisIdstring-Bind to a specific X-axis by ID
yAxisIdstring-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.

FieldTypeDescription
datumTOriginal data row
valuenumber | nullResolved numeric value (when applicable)
indexnumberPosition within the dataset
seriesIndexnumberOrder of this series within the chart
seriesIdstringDataset id
categorystring?Resolved category label, when applicable
sizenumber?Current marker pixel size, populated for marker accessors

#SegmentContext

Passed to per-segment callbacks (segmentColor, segmentStrokeWidth, segmentDash, segmentFillColor).

FieldTypeDescription
p0ComputedPointStart point of the segment
p1ComputedPointEnd point of the segment
p0DataIndexnumberData index of the start point
p1DataIndexnumberData index of the end point
datum0T?Underlying datum at p0DataIndex (when data passed)
datum1T?Underlying datum at p1DataIndex (when data passed)
seriesIdstring?Series id this segment belongs to
seriesIndexnumber?Series order index

#ComputedPoint

FieldTypeDescription
xnumberPixel X coordinate
ynumberPixel Y coordinate
valuenumber | nullRaw data value. null for gap points
categorystringCategory label
dataIndexnumberOriginal 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.

PropTypeDefaultDescription
mode'normal' | 'percent''normal'normal = absolute values stacked (negative values naturally stack downward). percent = normalized to 100%
gapnumber0Pixel gap between stacked series
idstringautoStack 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.

PropTypeDefaultDescription
colorFillValue-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
fillOpacity0–10.3Fill opacity for the range area
idstringautoRange group identifier

#ChartItem

Use ChartItem as children of ChartLine instead of a data array for inline data definitions.

PropTypeDescription
category-xstringX-axis category
value-ynumberY-axis value
category-ystringY-axis category
value-xnumberX-axis value
colorstringOverride color for this point

#PointRenderContext

Passed to the renderMarker callback for each data point.

FieldTypeDescription
xnumberPixel X coordinate of the point
ynumberPixel Y coordinate of the point
indexnumberData index
valuenumber | nullRaw data value
categorystringCategory label
dataTOriginal data item from the data array
colorstringResolved series color
sizenumberCurrent marker radius in pixels. Larger when hovered
isHoveredbooleanWhether this point is currently hovered
opacitynumberComputed opacity from hover dim effects (0–1). Apply to the custom marker to respect dimOpacity
ctxCanvasRenderingContext2D | undefinedCanvas context, present only in Canvas mode
drawImagefunction | undefinedDraw an image from a URL at a position relative to origin. Handles loading and caching. Canvas mode only
animatefunction | undefinedRegister a continuous animation on a numeric property. Drives the canvas RAF loop while active. Canvas mode only