nessra uinessra ui

Beautiful and responsive charts built with Recharts.

Loading...
"use client"

import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"

About

The Chart component is built using Recharts. It provides a set of composable chart components with built-in theming support.

Installation

pnpmnpmyarnbun
pnpm dlx shadcn@latest add https://nessra-ui.vercel.app/r/chart.json

Usage

import {
  ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart"
const chartConfig = {
  desktop: {
    label: "Desktop",
    color: "var(--chart-1)",
  },
} satisfies ChartConfig
 
export function MyChart() {
  return (
    <ChartContainer config={chartConfig}>
      <BarChart data={data}>
        <Bar dataKey="desktop" fill="var(--color-desktop)" />
        <ChartTooltip content={<ChartTooltipContent />} />
      </BarChart>
    </ChartContainer>
  )
}

Chart Config

The chart config defines labels, icons, and colors for each data series.

const chartConfig = {
  desktop: {
    label: "Desktop",
    color: "var(--chart-1)",
  },
  mobile: {
    label: "Mobile",
    color: "var(--chart-2)",
  },
} satisfies ChartConfig

Theme Colors

You can use theme colors from CSS variables:

const chartConfig = {
  desktop: {
    label: "Desktop",
    theme: {
      light: "#2563eb",
      dark: "#3b82f6",
    },
  },
}

Examples

Bar Chart

A basic bar chart with multiple data series.

Loading...
"use client"

import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"

With Legend

Add a legend to identify data series.

Loading...
"use client"

import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"

Line Chart

A line chart for showing trends over time.

Loading...
"use client"

import { CartesianGrid, Line, LineChart, XAxis } from "recharts"

Area Chart

An area chart with gradient fills.

Loading...
"use client"

import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"

Pie Chart

A pie chart for showing proportions.

Loading...
"use client"

import { Pie, PieChart } from "recharts"

Radar Chart

A radar chart for comparing multiple variables.

Loading...
"use client"

import { PolarAngleAxis, PolarGrid, Radar, RadarChart } from "recharts"

Theming

The chart components use CSS variables for colors. The following variables are available by default:

  • --chart-1 through --chart-5

These are defined in your globals.css with light and dark variants.

API Reference

ChartContainer

The main wrapper component that provides context and responsive sizing.

PropTypeDefaultDescription
configChartConfig-Configuration for the chart
childrenReactNode-Recharts chart component

ChartTooltip

Re-exported from Recharts with custom styling.

ChartTooltipContent

Custom tooltip content component.

PropTypeDefaultDescription
hideLabelbooleanfalseHide the tooltip label
hideIndicatorbooleanfalseHide the color indicator
indicator"line" | "dot" | "dashed""dot"Style of the color indicator
nameKeystring-Key to use for item names
labelKeystring-Key to use for label

ChartLegend

Re-exported from Recharts with custom styling.

ChartLegendContent

Custom legend content component.

PropTypeDefaultDescription
hideIconbooleanfalseHide the legend icon
nameKeystring-Key to use for names