Sankey chart
Themed flow diagrams with source, target, solid, or gradient links.
"use client";
import {
ChartcnSankeyChart,
Node,
NodeLabel,
Link,
Tooltip,
} from "@/components/charts/sankey-chart";
import type { SankeyData } from "@/components/charts/sankey-chart";
import type { ChartConfig } from "@/components/ui/chart";
// Marketing funnel - user acquisition to conversions
const data: SankeyData = {
links: [
{ source: 0, target: 3, value: 42000 },
{ source: 1, target: 3, value: 28000 },
{ source: 2, target: 3, value: 18000 },
{ source: 3, target: 4, value: 52000 },
{ source: 3, target: 7, value: 36000 },
{ source: 4, target: 5, value: 31000 },
{ source: 4, target: 7, value: 21000 },
{ source: 5, target: 6, value: 24000 },
{ source: 5, target: 7, value: 7000 },
],
nodes: [
{ name: "Organic" },
{ name: "PaidAds" },
{ name: "Social" },
{ name: "Landing" },
{ name: "Product" },
{ name: "Cart" },
{ name: "Purchase" },
{ name: "Bounced" },
],
};
const chartConfig = {
Bounced: {
colors: {
dark: ["#fb7185"],
light: ["#f43f5e"],
},
label: "Bounced",
},
Cart: {
colors: {
dark: ["#fb923c"],
light: ["#ea580c"],
},
label: "Cart",
},
Landing: {
colors: {
dark: ["#22d3ee"],
light: ["#0891b2"],
},
label: "Landing Page",
},
Organic: {
colors: {
dark: ["#34d399"],
light: ["#059669"],
},
label: "Organic Search",
},
PaidAds: {
colors: {
dark: ["#f87171"],
light: ["#dc2626"],
},
label: "Paid Ads",
},
Product: {
colors: {
dark: ["#60a5fa"],
light: ["#2563eb"],
},
label: "Product Page",
},
Purchase: {
colors: {
dark: ["#4ade80"],
light: ["#16a34a"],
},
label: "Purchase",
},
Social: {
colors: {
dark: ["#a78bfa"],
light: ["#7c3aed"],
},
label: "Social Media",
},
} satisfies ChartConfig;
export function ChartcnExampleSankeyChart() {
return (
<ChartcnSankeyChart
className="h-full w-full p-4"
data={data}
config={chartConfig}
>
<Node isClickable>
<NodeLabel position="outside" showValues />
</Node>
<Link variant="source" />
<Tooltip />
</ChartcnSankeyChart>
);
}Install
$ pnpm dlx shadcn@latest add @chartcn/sankey-chart
Numeric link indices are converted to ECharts node names. Node labels can live inside or outside the flow and optionally include aggregated values.