"use client" import { Bar, BarChart, XAxis } from "recharts" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/registry/new-york-v4/ui/card" import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig, } from "@/registry/new-york-v4/ui/chart" export const description = "A stacked bar chart with a legend" const chartData = [ { date: "2024-07-15", running: 450, swimming: 300 }, { date: "2024-07-16", running: 380, swimming: 420 }, { date: "2024-07-17", running: 520, swimming: 120 }, { date: "2024-07-18", running: 140, swimming: 550 }, { date: "2024-07-19", running: 600, swimming: 350 }, { date: "2024-07-20", running: 480, swimming: 400 }, ] const chartConfig = { running: { label: "Running", color: "var(--chart-1)", }, swimming: { label: "Swimming", color: "var(--chart-2)", }, } satisfies ChartConfig export function ChartTooltipAdvanced() { return ( Tooltip - Advanced Tooltip with custom formatter and total. { return new Date(value).toLocaleDateString("en-US", { weekday: "short", }) }} /> ( <>
{chartConfig[name as keyof typeof chartConfig]?.label || name}
{value} kcal
{/* Add this after the last item */} {index === 1 && (
Total
{item.payload.running + item.payload.swimming} kcal
)} )} /> } cursor={false} defaultIndex={1} /> ) }