Add to an existing app
Your app doesn't need to be a shadcn/ui project, use Tailwind, or change its styles. The charts are plain React files with one stylesheet of their own (scoped to .clui), so they sit next to whatever you already have.
Don't run npx shadcn init in an existing app. It's meant for new shadcn projects: it rewrites your global CSS, adds Tailwind and its theme variables, and creates lib/utils. You only need a components.json the CLI can read.
1. Add a minimal components.json
Create it at the root of the project (next to package.json):
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": { "config": "", "css": "", "baseColor": "neutral", "cssVariables": true },
"aliases": { "components": "@/components", "utils": "@/lib/utils" },
"registries": { "@chartslibraryui": "https://chartslibraryui.com/r/{name}.json" }
}- The
tailwindblock must be there for the CLI to accept the file, but with empty paths it changes nothing: our charts bring no Tailwind classes and no CSS variables to merge. aliases.componentsis where files go:@/componentsputs charts incomponents/charts/(orsrc/components/charts/when@/points tosrc/). Match yourtsconfig.jsonpaths. No@/alias? Use a relative folder through the CLI's--path, or the chartslibraryui CLI below.rsckeeps the"use client"line at the top of each chart. Leave ittrue, even in Vite: the line is harmless there.- For Pro, replace the
registriesentry with the one that sends your key (see Pro charts).
2. Install a chart
pnpm dlx shadcn@latest add @chartslibraryui/line-chartnpx shadcn@latest add @chartslibraryui/line-chartyarn dlx shadcn@latest add @chartslibraryui/line-chartbunx --bun shadcn@latest add @chartslibraryui/line-chartThis writes components/charts/line-chart.tsx and components/charts/core/*, and nothing else. Check with --dry-run first if you like.
3. Import the stylesheet once
In your root layout or entry file:
import "@/components/charts/core/charts.css"; // or a relative pathAll its rules are scoped to .clui, and its colours are CSS variables you can override in your own CSS (see Theming). It doesn't reset or restyle anything outside the charts.
4. Use it
import { LineChart } from "@/components/charts/line-chart";
<LineChart title="Revenue is ahead of plan" data={rows} x="month" series={["revenue", "plan"]} format="currency" />For a locale or currency other than en-US/USD, wrap the app once in <ChartsProvider locale currency> (see Number formatting).
Without components.json
The chartslibraryui CLI needs no config file at all:
pnpm dlx chartslibraryui add line-chart bar-chart --dir src/components/chartsnpx chartslibraryui add line-chart bar-chart --dir src/components/chartsyarn dlx chartslibraryui add line-chart bar-chart --dir src/components/chartsbunx --bun chartslibraryui add line-chart bar-chart --dir src/components/chartsOr copy the files by hand from each chart page's Source section (see Installation).
Checklist
- React 18 or 19. TypeScript recommended (the files are
.tsx);strictmode is fine. - No new npm dependencies.
- Next.js App Router: render charts from server components freely; they're client components already.
- When you update later, see Upgrading: updates replace the chart files, so keep your changes outside
components/charts/.