Area Chart

Learn how to implement and customize Area Charts in your Nuxt application using Vue charts.

The AreaChart component is a powerful addition to the Vue charts library, visualizing time series or categorical data as filled line charts. It supports reactive data and TypeScript, making it ideal for interactive dashboards.

Basic Usage

Basic Single Line

Basic Area Chart

Step Area Chart

Props

PropTypeDefaultDescription
dataT[]RequiredArray of data points for the chart. Each element represents a data point.
heightnumberRequiredHeight of the chart in pixels.
xLabelstringundefinedOptional label for the x-axis.
yLabelstringundefinedOptional label for the y-axis.
padding{ top: number; right: number; bottom: number; left: number; }undefinedOptional padding for the chart (top, right, bottom, left).
categoriesRecord<string, BulletLegendItemInterface>RequiredSeries configuration: name and color for each data key.
markerConfigRecord<string, MarkerConfig>{}Marker configuration for each series.
xFormatteraxisFormatterundefinedFormats X-axis labels. (tick, i, ticks) => string where tick can be a number or Date.
yFormatteraxisFormatterundefinedFormats Y-axis labels. (tick, i, ticks) => string where tick can be a number or Date.
curveTypeCurveTypeundefinedType of curve interpolation (see Curve Types section).
hideAreabooleanfalseIf true, hides the area fill and shows only the line.
gradientStopsArray<{ offset: string; stopOpacity: number }>undefinedCustom gradient stops for the area fill.
lineWidthnumber2Width of the line in pixels.
lineDashArraynumber[][]undefinedSVG stroke-dasharray for dashed lines.
xNumTicksnumberundefinedDesired number of ticks on the x-axis.
xExplicitTicks`(numberstringDate)`
minMaxTicksOnlybooleanfalseIf true, only show first and last ticks on the x-axis.
yNumTicksnumberundefinedDesired number of ticks on the y-axis.
hideLegendbooleanfalseIf true, hides the chart legend.
hideTooltipbooleanfalseIf true, hides the chart tooltip.
legendPositionLegendPositionundefinedPosition of the legend (see LegendPosition).
legendStylestring | Record<string, string>undefinedCustom CSS style for the legend container.
xDomainLinebooleanfalseShow domain (axis) line on the x-axis.
yDomainLinebooleanfalseShow domain (axis) line on the y-axis.
xTickLinebooleanfalseShow tick lines on the x-axis.
yTickLinebooleanfalseShow tick lines on the y-axis.
xGridLinebooleanfalseShow grid lines on the x-axis.
yGridLinebooleanfalseShow grid lines on the y-axis.
hideXAxisbooleanfalseIf true, hides the x-axis.
hideYAxisbooleanfalseIf true, hides the y-axis.
crosshairConfigCrosshairConfigundefinedCrosshair configuration for customizing the crosshair line.
xAxisConfigAxisConfigundefinedAxis configuration for customizing the appearance of the x-axis.
yAxisConfigAxisConfigundefinedAxis configuration for customizing the appearance of the y-axis.
yDomain[number | undefined, number | undefined]undefinedDomain for the y-axis.
xDomain[number | undefined, number | undefined]undefinedDomain for the x-axis.

Data Format

The data should be an array of objects where each object represents a data point:

types.ts
interface AreaChartData {
  [key: string]: string | number
}

Categories Format

Categories define the visual appearance and metadata for each area:

types.ts
interface AreaCategory {
  name: string
  color: string
}

interface AreaCategories {
  [key: string]: AreaCategory
}

Curve Types

Available curve types for area interpolation:

  • linear - Straight lines between points
  • linearClosed - Closed straight lines
  • basis - B-spline curves
  • basisClosed - Closed B-spline curves
  • basisOpen - Open B-spline curves
  • bundle - Bundle spline curves
  • cardinal - Cardinal spline curves
  • cardinalClosed - Closed cardinal spline curves
  • cardinalOpen - Open cardinal spline curves
  • catmullRom - Catmull-Rom spline curves
  • catmullRomClosed - Closed Catmull-Rom spline curves
  • catmullRomOpen - Open Catmull-Rom spline curves
  • monotoneX - Monotone cubic interpolation (X axis)
  • monotoneY - Monotone cubic interpolation (Y axis)
  • natural - Natural cubic spline
  • step - Step function
  • stepBefore - Step function (step before)
  • stepAfter - Step function (step after)

Stacked Areas

To create stacked area charts, simply include multiple data series in your categories. This approach makes it easy to visualize cumulative data trends in Vue and Nuxt applications:

stacked-area.vue
<script setup lang="ts">
const data = [
  { month: 'Jan', desktop: 100, mobile: 80, tablet: 40 },
  { month: 'Feb', desktop: 120, mobile: 90, tablet: 50 },
  { month: 'Mar', desktop: 180, mobile: 110, tablet: 60 },
]

const categories = {
  desktop: { name: 'Desktop', color: '#3b82f6' },
  mobile: { name: 'Mobile', color: '#10b981' },
  tablet: { name: 'Tablet', color: '#f59e0b' },
}
</script>

<template>
  <AreaChart
    :data="data"
    :categories="categories"
    :height="300"
  />
  
</template>