Skip to main content
Location: sabo/src/components/dashboard/chart-area-interactive.tsx

When to use

  • Visualize KPIs and time-series within dashboard sections.

Usage

Styling tip

  • Define series colors via ChartContainer config for light/dark theme parity.

Key features

  • Theme-aware colors: Define colors via ChartConfig for automatic light/dark mode support
  • Recharts integration: Uses Recharts components (AreaChart, LineChart, BarChart) inside ChartContainer
  • Interactive: Supports tooltips, legends, and click handlers
  • Responsive: Container queries adjust sizing based on available space

Steps

1

Create chart config

Define series with labels and colors. Colors can be simple strings or theme-specific objects:
Use CSS variables like var(--color-revenue) in Recharts components to reference these colors.
2

Prepare data

Start with static arrays. Later, fetch from Supabase or your API. Ensure keys match ChartConfig series names.
3

Format axes and tooltips

Use Recharts’ tickFormatter for axes and Tooltip content formatters:
Use Intl.NumberFormat and Intl.DateTimeFormat for locale-aware, accessible formatting.
4

Add interactivity

Enable tooltips, legends, and click handlers for drill-down:

Troubleshooting

  • Colors not changing with theme
    • Ensure you’re using var(--color-{series}) in Recharts components
  • Chart not responsive
    • Wrap in ChartContainer with className height/width
  • Data not showing
    • Verify dataKey props match your data object keys exactly