home / skills / dennisadriaans / vue-chrts / line-area-chart

line-area-chart skill

/.claude/skills/line-area-chart

This skill helps you build reusable line and area charts in Vue 3, enabling time-series visualization with flexible formatting and legends.

npx playbooks add skill dennisadriaans/vue-chrts --skill line-area-chart

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.3 KB
---
name: line-area-chart
description: Build LineChart and AreaChart components. Use for time series, trends, and continuous data visualization.
---

# LineChart & AreaChart

LineChart and AreaChart share the same API. LineChart is essentially AreaChart with `hideArea: true`.

## Data Structure Pattern

```
┌──────────────────────────────────────────────────────────┐
│  DATA FLOW                                               │
│                                                          │
│  Raw Data Array          Categories Config               │
│  ┌─────────────┐        ┌──────────────────┐            │
│  │ { x, y1, y2 }│   +   │ y1: {name, color}│  →  Chart  │
│  │ { x, y1, y2 }│       │ y2: {name, color}│            │
│  │ ...         │        └──────────────────┘            │
│  └─────────────┘                                        │
└──────────────────────────────────────────────────────────┘
```

## Complete Example

```vue
<script setup lang="ts">
import { LineChart, CurveType, LegendPosition } from 'vue-chrts'

interface DataItem {
  date: string
  desktop: number
  mobile: number
}

const data: DataItem[] = [
  { date: '2024-01-01', desktop: 186, mobile: 120 },
  { date: '2024-01-02', desktop: 305, mobile: 250 },
  { date: '2024-01-03', desktop: 237, mobile: 180 },
  { date: '2024-01-04', desktop: 273, mobile: 220 },
  { date: '2024-01-05', desktop: 209, mobile: 170 },
]

const categories = {
  desktop: { name: 'Desktop', color: '#3b82f6' },
  mobile: { name: 'Mobile', color: '#10b981' }
}

const xFormatter = (tick: number) => {
  const item = data[tick]
  return new Date(item.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
}

const yFormatter = (tick: number) => `${tick.toLocaleString()}`
</script>

<template>
  <LineChart
    :data="data"
    :categories="categories"
    :height="300"
    :xFormatter="xFormatter"
    :yFormatter="yFormatter"
    :curveType="CurveType.MonotoneX"
    :legendPosition="LegendPosition.TopRight"
    xLabel="Date"
    yLabel="Visitors"
    :xNumTicks="5"
    :yNumTicks="4"
    :yGridLine="true"
  />
</template>
```

## AreaChart Specific Features

```vue
<!-- Stacked area chart -->
<AreaChart
  :data="data"
  :categories="categories"
  :height="300"
  :stacked="true"
  :xFormatter="xFormatter"
/>

<!-- Custom gradient stops -->
<AreaChart
  :data="data"
  :categories="categories"
  :height="300"
  :gradientStops="[
    { offset: '0%', stopOpacity: 0.4 },
    { offset: '100%', stopOpacity: 0.05 }
  ]"
/>

<!-- Hide area (becomes LineChart) -->
<AreaChart
  :data="data"
  :categories="categories"
  :height="300"
  :hideArea="true"
/>
```

## Key Props Reference

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data` | `T[]` | required | Array of data objects |
| `categories` | `Record<string, BulletLegendItem>` | required | Map of data keys to display config |
| `height` | `number` | required | Chart height in pixels |
| `curveType` | `CurveType` | `Linear` | Line interpolation style |
| `lineWidth` | `number` | `2` | Stroke width of lines |
| `lineDashArray` | `number[][]` | `undefined` | Dashed line patterns per series |
| `stacked` | `boolean` | `false` | Stack areas on top of each other |
| `hideArea` | `boolean` | `false` | Show only lines (AreaChart only) |
| `gradientStops` | `Array<{offset, stopOpacity}>` | default gradient | Custom fill gradient |
| `xFormatter` | `(tick, i?, ticks?) => string` | - | X-axis label formatter |
| `yFormatter` | `(tick, i?, ticks?) => string` | - | Y-axis label formatter |
| `tooltipTitleFormatter` | `(data: T) => string` | - | Custom tooltip title |
| `xNumTicks` | `number` | auto | Desired x-axis tick count |
| `yNumTicks` | `number` | auto | Desired y-axis tick count |
| `minMaxTicksOnly` | `boolean` | `false` | Show only first/last x ticks |
| `xGridLine` | `boolean` | `false` | Show vertical grid lines |
| `yGridLine` | `boolean` | `false` | Show horizontal grid lines |
| `xDomainLine` | `boolean` | `true` | Show x-axis line |
| `yDomainLine` | `boolean` | `true` | Show y-axis line |
| `hideLegend` | `boolean` | `false` | Hide the legend |
| `hideTooltip` | `boolean` | `false` | Hide tooltips |
| `legendPosition` | `LegendPosition` | `TopRight` | Legend placement |

## Curve Types Cheat Sheet

```
Linear ────────    MonotoneX ∿∿∿∿∿    Step ┌─┐┌─┐
  Best for:         Best for:           Best for:
  Discrete data     Smooth trends       Discrete states
  
Natural ~~~~~      Basis ∼∼∼∼∼        Cardinal ≈≈≈≈
  Best for:         Best for:           Best for:
  Flowing curves    Extra smooth        Balanced curves
```

## Common Gotchas

1. **X-axis shows numbers instead of labels**: You forgot `xFormatter`
2. **Only one series shows**: Categories keys must match data object keys exactly
3. **Tooltip shows wrong info**: Use `tooltipTitleFormatter` for custom display
4. **Lines look jagged**: Try `CurveType.MonotoneX` instead of `Linear`

Overview

This skill builds LineChart and AreaChart components for Vue 3 applications to visualize time series, trends, and continuous data. It provides a shared API where LineChart is an AreaChart variant with the area fill hidden, enabling consistent configuration across both chart types. The components are designed for clear, configurable displays of multiple series with legends, tooltips, and axis formatting.

How this skill works

Provide an array of data objects and a categories map that defines each series (label and color). The chart renders lines and optional filled areas, supports stacking, custom gradients, and multiple curve interpolation types. Format axis labels and tooltips via provided formatter callbacks, and control ticks, grid lines, legends, and other visual options through props.

When to use it

  • Displaying trends or patterns over time (daily, weekly, monthly data).
  • Comparing multiple continuous series (desktop vs mobile, revenue vs cost).
  • Showing cumulative or stacked contributions across categories.
  • When you need configurable axis formatting and custom tooltips.

Best practices

  • Always supply a categories map whose keys match the data object fields exactly.
  • Use xFormatter to convert numeric tick indices into readable dates or labels.
  • Choose CurveType.MonotoneX for smooth trend lines and Linear for discrete points.
  • Limit the number of series shown to keep the legend and lines readable.
  • Provide yFormatter for locale-aware numbers and tooltipTitleFormatter for custom tooltip headers.

Example use cases

  • Daily visitors line chart with separate series for desktop and mobile.
  • Stacked area chart showing product revenue contributions over a quarter.
  • Smoothing noisy measurements with monotone curve interpolation.
  • Small multiples of line charts with consistent height and tick counts.
  • Area chart with custom gradient stops to emphasize recent values.

FAQ

Why does the x-axis show numbers instead of my labels?

Pass an xFormatter that maps each numeric tick to a human-readable label (for example, formatting a date string).

Only one series is visible — what happened?

Ensure the keys in your categories object exactly match the property names in each data item; mismatched keys hide series.