Skip to main content
UsageTrend draws one bar per past billing period, oldest first, labelled with the period’s start date and its amount or units. From React 0.11.0. When to use
  • A usage history section of your billing settings.
  • Beside UsageBreakdown to compare this period with earlier ones.
  • A chart of one feature’s units over time, with featureCode.
UsageTrend with five monthly bars from $7.20 to $17.32, light theme

Importing UsageTrend

Rendering UsageTrend

Inside a BillingProvider with billingEndpoint, read past periods with useUsage({ period: 'past' }) and pass them in:
app/billing/history/page.tsx
Periods can come in any order; they are sorted by start date. Bars scale to the largest period, and each bar has an accessible label with its date and value. Dates show in UTC in en-US.

Data

periods is a list of CustomerUsageData, one per billing period, as in the usage_periods of Core’s past-usage endpoint. Amounts are in cents; units is a decimal string.

Live data

useUsage({ period: 'past' }) reads past periods for the signed-in customer through your billingEndpoint; periods sets how many. Its data is the list of periods and passes to periods directly:
Without the hooks, read GET https://api.nozle.app/core/api/v1/customers/{external_customer_id}/past_usage on your backend with a secret key and pass its usage_periods. It takes periods_count and feature_code.

Examples

Units of one feature

With featureCode, each bar shows that feature’s units in the period instead of the amount, for example “29,800 api_calls”. Periods without the feature show zero.
UsageTrend with the API call units of five months, light theme

Loading, empty and error

isLoading shows a loading placeholder, an empty list shows emptyMessage, and error shows the message as an alert.
UsageTrend loading placeholder, No past usage yet message, and an error message, light theme

API reference

CustomerUsageData[] | null
The periods to chart, in any order. Empty or missing shows the empty message.
string
Charts the units of this feature instead of the amount. Bars read “29,800 api_calls”.
boolean
default:false
Shows a loading placeholder.
Error | string | null
Shows the message as an alert. Defaults to null.
string
default:"No past usage yet."
Shown when there are no periods.
Appearance
Theme, variables and element overrides. Defaults to the provider’s. See Appearance.

States

Appearance

usageTrend (root), usageTrend__bar (each bar).Style them with appearance.elements. See Elements.

UsageBreakdown

This period’s units and amounts.

UsageDashboard

Usage against limits.