Billing History Chart
A billing trend chart drawn as a hand-rolled SVG line with a monthly/quarterly toggle above it. Switching periods swaps the dataset and redraws the line, while the total and a trend arrow above the chart compare the most recent point to the one before it. A visually hidden table mirrors the same data for screen readers.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/billing-history-chart.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing64.tsx instead.
Usage
The file also exports billing64Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Billing64, billing64Demo } from "@/components/blocks/billing/billing64"; export default function Page() { return <Billing64 {...billing64Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Spending history" | Card heading. |
| description | string | none | Optional supporting text under the heading. |
| monthlyPoints | HistoryPoint[] | none | Data points shown when the monthly toggle is active. |
| quarterlyPoints | HistoryPoint[] | none | Data points shown when the quarterly toggle is active. |
| defaultPeriod | "monthly" | "quarterly" | "monthly" | Which dataset is active on first render. |
| currencySymbol | string | "$" | Symbol prefixed to every formatted amount. |
| className | string | none | Extra classes for the outer container. |
Types
interface HistoryPoint { label: string; amount: number; }
Behavior notes
- Switching the monthly/quarterly toggle swaps which points array is used and redraws the SVG path and circles; there's no built-in transition between datasets.
- The total shown above the chart is the sum of the currently active dataset's amounts, not a fixed value.
- The trend arrow and percentage compare only the last two points of the active dataset. With fewer than two points it shows a flat (no-change) indicator.
- The line is a plain SVG path scaled to the active dataset's own maximum value, so the vertical scale resets when switching periods rather than sharing one fixed axis.
- Each data point renders a native SVG <title> for hover text, and a visually hidden table below the chart lists every point's label and amount for screen readers.
Frequently asked questions
More Billing Blocks
View all →Billing Invoice List
Invoice history table with status badges, formatted amounts, and a per-row download link, built with shadcn/ui and Tailwind CSS.
Billing Failed Payment Alert
High-contrast failed-payment alert with a message, a retry button, and an optional update-payment-method button, built with shadcn/ui and Tailwind CSS.
Billing Credit Balance
Compact credit balance card with a large total, an optional purchased-versus-promotional breakdown, a low-balance notice, and a top-up button.
Billing Payment Methods
A saved payment method list for React and Next.js with brand icons, a default badge, near-expiry warnings, and remove/set-default actions per row.
Billing Add Card
A card entry form for React and Next.js with auto-formatted fields, internal brand detection, and per-field validation feedback built with shadcn/ui and Tailwind CSS.
Billing Coupon Code
An inline promo code input for React and Next.js with a simulated loading state, an applied summary showing the discount amount, and an invalid-code message.