{
  "title": "Bar Chart Multiple",
  "description": "A grouped bar chart comparing desktop and mobile visitors over 6 months built with TanStack Charts.",
  "name": "tanstack-charts-bar-multiple",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/bar/bar-chart-multiple.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, barY, defineChart, group } from \"@tanstack/charts\";\nimport { motion } from \"@tanstack/charts/motion\";\nimport { tooltip } from \"@tanstack/charts/tooltip\";\nimport { Chart } from \"@tanstack/react-charts/core\";\nimport { useMemo } from \"react\";\n\nimport { scaleBand, scaleLinear } from \"d3-scale\";\nimport { TrendingUp } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\nconst twoSeries = [\"desktop\", \"mobile\"] as const;\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData() {\n    return [\n        { month: \"January\", value: 186, series: \"desktop\" },\n        { month: \"January\", value: 80, series: \"mobile\" },\n        { month: \"February\", value: 305, series: \"desktop\" },\n        { month: \"February\", value: 200, series: \"mobile\" },\n        { month: \"March\", value: 237, series: \"desktop\" },\n        { month: \"March\", value: 120, series: \"mobile\" },\n        { month: \"April\", value: 73, series: \"desktop\" },\n        { month: \"April\", value: 190, series: \"mobile\" },\n        { month: \"May\", value: 209, series: \"desktop\" },\n        { month: \"May\", value: 130, series: \"mobile\" },\n        { month: \"June\", value: 214, series: \"desktop\" },\n        { month: \"June\", value: 140, series: \"mobile\" },\n    ];\n}\n\nfunction shadcnXAxis() {\n    return {\n        scale: () => scaleBand<string>().paddingInner(0.2).paddingOuter(0.1),\n        axis: {\n            line: false,\n            ticks: {\n                size: 0,\n                padding: 10,\n                format: (value: string) => value.slice(0, 3),\n            },\n        },\n    };\n}\n\nfunction shadcnTheme() {\n    return {\n        foreground: \"var(--muted-foreground)\",\n        grid: \"var(--border)\",\n        background: \"transparent\",\n    };\n}\n\nfunction titleCase(value: string) {\n    return value.charAt(0).toUpperCase() + value.slice(1);\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    return {\n        title: String(points[0]?.xValue ?? \"\"),\n        rows: points.map((point) => ({\n            label: titleCase(\n                String(point.group ?? point.markId.replace(/-?(bars|lines|areas|slices|values|radar)$/u, \"\")),\n            ),\n            value: Number(point.yValue ?? point.xValue ?? 0).toLocaleString(\"en-US\"),\n            color: point.color,\n        })),\n    };\n}\n\nexport function BarChartMultiple() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(() => {\n        const groupScale = scaleBand<string>().domain(twoSeries).paddingInner(0.08).paddingOuter(0);\n\n        return defineChart(\n            {\n                renderer: motionRenderer,\n                motion: {\n                    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n                },\n                marks: [\n                    barY(data, {\n                        id: \"visitor-bars\",\n                        x: \"month\",\n                        y: \"value\",\n                        z: \"series\",\n                        color: \"series\",\n                        key: (row) => `${row.month}:${row.series}`,\n                        layout: group({ scale: groupScale }),\n                        radius: 4,\n                    }),\n                ],\n                scales: {\n                    x: shadcnXAxis(),\n                    y: { scale: scaleLinear, grid: true, axis: false },\n                },\n                color: { domain: twoSeries, range: [\"var(--chart-1)\", \"var(--chart-2)\"] },\n                margin: { top: 10, right: 10, bottom: 30, left: 10 },\n                theme: shadcnTheme(),\n            },\n            {\n                focus: \"group-x\",\n                tooltip: {\n                    use: tooltip,\n                    motion: { type: \"spring\", stiffness: 170, damping: 18 },\n                    className: \"font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs\",\n                    anchor: \"group-center\",\n                    placement: \"auto\",\n                    sort: \"color-domain\",\n                    content: (points) => shadcnTooltipContent(points),\n                },\n            },\n        );\n    }, [data]);\n\n    return (\n        <Card className=\"w-full max-w-2xl\">\n            <CardHeader>\n                <CardTitle>Checkout Platform Conversion</CardTitle>\n                <CardDescription>Desktop vs Mobile completed checkout orders</CardDescription>\n            </CardHeader>\n            <CardContent>\n                <div className=\"h-[300px] w-full\">\n                    <Chart\n                        definition={definition}\n                        renderer={motionRenderer}\n                        height={300}\n                        ariaLabel=\"Checkout Platform Conversion Chart\"\n                    />\n                </div>\n            </CardContent>\n            <CardFooter className=\"flex-col items-start gap-2 text-sm\">\n                <div className=\"flex items-center gap-2 leading-none font-medium\">\n                    Mobile checkout completions up by 5.2% this month{\" \"}\n                    <TrendingUp className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">Showing total visitors for the last 6 months</div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default BarChartMultiple;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. A grouped bar chart comparing desktop and mobile visitors over 6 months built with TanStack Charts. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "bar"
    ]
  }
}