{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-04",
  "description": "A single series of bars with the latest period highlighted and labelled, against a goal line.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/chart-panel/chart-panel-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartAxisProps,\n  chartBarCursor,\n  chartBarValueLabel,\n  chartFadedColor,\n  chartGridProps,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n  type ChartValueFormatter,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIChange, KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCompact,\n  formatCurrency,\n  formatNumber,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  Cell,\n  LabelList,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface MonthValue {\n  label: string\n  value: number\n}\n\ninterface ChartPanel4Props extends BlockStateProps {\n  /** Leave out, or pass no months, to show the empty state. */\n  data?: MonthValue[]\n  description: string\n  formatter?: ChartValueFormatter\n  /** A target drawn as a line across the bars, and said in words against the latest value. */\n  goal?: { label: string; value: number }\n  title: string\n}\n\nconst exampleProps: ChartPanel4Props = {\n  data: [\n    { label: 'Oct', value: 31_200 },\n    { label: 'Nov', value: 33_900 },\n    { label: 'Dec', value: 34_400 },\n    { label: 'Jan', value: 37_100 },\n    { label: 'Feb', value: 39_800 },\n    { label: 'Mar', value: 41_300 },\n    { label: 'Apr', value: 44_900 },\n    { label: 'May', value: 46_200 },\n    { label: 'Jun', value: 49_700 },\n    { label: 'Jul', value: 52_100 },\n    { label: 'Aug', value: 55_600 },\n    { label: 'Sep', value: 59_400 },\n  ],\n  description: 'Monthly recurring revenue at the end of each of the last 12 months.',\n  formatter: (value) => formatCurrency(value),\n  goal: { label: 'Goal', value: 60_000 },\n  title: 'MRR',\n}\n\nconst HIGHLIGHT_COLOR = 'var(--color-chart-2)'\nconst MUTED_COLOR = chartFadedColor(HIGHLIGHT_COLOR)\n\nconst ChartPanel4 = (props: ChartPanel4Props) => {\n  const {\n    data = [],\n    description,\n    formatter = (value) => formatNumber(value),\n    goal,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const lastIndex = data.length - 1\n  const latest = data[lastIndex]\n  const prior = data[lastIndex - 1]\n  const gap = latest && goal ? goal.value - latest.value : 0\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={getBlockState(status, data)}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <BlockReady className='w-16 text-sm'>\n                <p className='text-muted-foreground text-sm'>{latest?.label}</p>\n              </BlockReady>\n              <KPIValue value={latest?.value} format={formatter} />\n              <KPIChange\n                comparison={`in ${prior?.label}`}\n                previous={prior?.value}\n                value={latest?.value}\n              />\n              {goal && (\n                <BlockReady className='text-sm'>\n                  {latest && (\n                    <p className='text-muted-foreground text-sm'>\n                      {gap > 0\n                        ? `${formatter(gap)} short of the ${formatter(goal.value)} ${goal.label.toLowerCase()}.`\n                        : `${formatter(-gap)} past the ${formatter(goal.value)} ${goal.label.toLowerCase()}.`}\n                    </p>\n                  )}\n                </BlockReady>\n              )}\n            </div>\n            <ChartPanelFigure className='h-64'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <BarChart\n                  aria-label={`${title} chart`}\n                  data={data}\n                  margin={{ top: 24, right: 8, bottom: 0, left: 0 }}\n                >\n                  <CartesianGrid {...chartGridProps} />\n                  <XAxis {...chartAxisProps} dataKey='label' />\n                  <YAxis\n                    {...chartAxisProps}\n                    domain={[0, 'auto']}\n                    tickFormatter={(value: number) => formatCompact(value)}\n                    width={chartValueAxisWidth}\n                  />\n                  <Tooltip\n                    content={(tooltipProps) => (\n                      <ChartTooltipContent {...tooltipProps} valueFormatter={formatter} />\n                    )}\n                    cursor={chartBarCursor}\n                  />\n                  <Bar dataKey='value' maxBarSize={28} name={title} radius={[4, 4, 0, 0]}>\n                    {data.map((point, index) => (\n                      <Cell\n                        key={point.label}\n                        fill={index === lastIndex ? HIGHLIGHT_COLOR : MUTED_COLOR}\n                      />\n                    ))}\n                    <LabelList\n                      dataKey='value'\n                      content={chartBarValueLabel(lastIndex, formatCompact)}\n                    />\n                  </Bar>\n                  {goal && (\n                    <ReferenceLine\n                      {...chartReferenceProps}\n                      ifOverflow='extendDomain'\n                      y={goal.value}\n                      label={{\n                        ...chartReferenceLabel,\n                        value: `${goal.label} ${formatCompact(goal.value)}`,\n                        position: 'insideBottomLeft',\n                        dy: -4,\n                      }}\n                    />\n                  )}\n                </BarChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}${goal ? ` ${goal.label}: ${formatter(goal.value)}.` : ''}`}\n              columns={[\n                { key: 'label', label: 'Month' },\n                { format: formatter, key: 'value', label: title },\n              ]}\n              rows={data}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { ChartPanel4, exampleProps as chartPanel4ExampleProps, type ChartPanel4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-04.tsx"
    }
  ],
  "meta": {
    "shows": "A single series of bars with the latest period highlighted and labelled, against a goal line.",
    "size": "full",
    "usedWith": [
      "stat-group-02",
      "funnel-03",
      "activity-feed-01"
    ],
    "component": "ChartPanel4",
    "props": "{ data?: { label: string; value: number }[]; description: string; formatter?: (value: number) => string; goal?: { label: string; value: number }; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
