Getting Started

Set up D3 UI in your React or Next.js project with Tailwind CSS and D3.js.

Prerequisites

  • Node.js 18+ and npm/pnpm
  • React project (Next.js recommended)
  • Tailwind CSS installed

Install Tailwind CSS

Follow the official Tailwind setup guide if you haven’t already.

Install D3.js

Installing d3
npm install d3

Add Shared Types

Copy the shared types into your components/types.ts file. These types are used across all D3 UI components.

./components/types.ts

Add Utility Functions

Add the following helper function to components/lib/utils.tsx.

./components/lib/utils.tsx
export function cn(...classes: (string | undefined | false | null)[]) {
  return classes.filter(Boolean).join(" ");
}

Add Custom Hooks

Add these hooks to components/hooks/ for seamless transitions and animations.

./components/hooks/useTransition.tsx
./components/hooks/useGroupTransition.tsx

Add Primitive Components

The following primitives are used as building blocks for all charts. Place them in components/primitives/.

./components/primitives/Axis.tsx
./components/primitives/Tooltip.tsx
./components/primitives/Legend.tsx
./components/primitives/Label.tsx

Use the Chart Components

Now you can copy any chart component from our docs into your project’s components/ folder:

src/
  components/
    BarChart.tsx

Example Usage

import BarChart from "@/components/BarChart";
import { BarData } from "@/components/types";

const data: BarData = {
  "Sales": {
    label: "Monthly Sales",
    data: [
      { x: "Jan", y: 10 },
      { x: "Feb", y: 30 },
      { x: "Mar", y: 20 },
    ],
  }
};

export default function Example() {
  return (
    <div className="h-96 w-full">
      <BarChart data={data} title="Monthly Sales Overview" />
    </div>
  );
}

That’s it! You’ve set up the core of D3 UI. Explore the rest of the charts in documentation to start building your dashboard.