> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nozle.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# UsageTrend

> A bar chart of past billing periods: the amount of each period, or the units of one feature.

`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`](/sdks/react/components/usage-breakdown) to compare this period with earlier ones.
* A chart of one feature's units over time, with `featureCode`.

**Light**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, light theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/light.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=575e0d36f12318eb1ab2cb2042088994)

**Dark**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, dark theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/dark.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=185cb7f9c97309ccf831bf784648941a)

**Minimal**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, minimal theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/minimal.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=8f6ef937a481aa2462638a456da2a998)

**Neobrutal**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, neobrutal theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/neobrutal.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=63fb007cb36a4e6bfcd74a21487893ab)

**Nozle**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, nozle theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/nozle.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=7246b234e4f80ee411fd36861c3a13f7)

**Nozle Dark**

![UsageTrend with five monthly bars from \$7.20 to \$17.32, nozleDark theme](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend/nozle-dark.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=801f1cafacbd8de4c8aa7b28a28b6b19)

## Importing UsageTrend

```tsx theme={null}
import {
  UsageTrend,
  useUsage,
  type CustomerUsageData,
} from '@nozle-js/react'
```

## Rendering UsageTrend

Inside a `BillingProvider` with `billingEndpoint`, read past periods with `useUsage({ period: 'past' })` and pass them in:

```tsx app/billing/history/page.tsx theme={null}
'use client'
import { BillingProvider } from '@nozle-js/react'

function History() {
  const { data, isPending, error } = useUsage({ period: 'past', periods: 6 })
  return <UsageTrend periods={data} isLoading={isPending} error={error} />
}

export default function HistoryPage() {
  return (
    <BillingProvider publishableKey="pk_nozle_..." billingEndpoint="/api/nozle">
      <History />
    </BillingProvider>
  )
}
```

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.

```tsx theme={null}
const period = (from: string, to: string, apiCalls: number): CustomerUsageData => ({
  from_datetime: from,
  to_datetime: to,
  currency: 'USD',
  amount_cents: Math.round(apiCalls * 0.04),
  charges_usage: [
    {
      units: String(apiCalls),
      amount_cents: Math.round(apiCalls * 0.04),
      amount_currency: 'USD',
      charge: { nozle_id: `chg_${from}`, charge_model: 'standard' },
      feature: { nozle_id: 'ftr_api', code: 'api_calls', name: 'API calls' },
    },
  ],
})

const periods: CustomerUsageData[] = [
  period('2026-08-01T00:00:00Z', '2026-08-31T23:59:59Z', 26400),
  period('2026-09-01T00:00:00Z', '2026-09-30T23:59:59Z', 29800),
]

export function History() {
  return <UsageTrend periods={periods} />
}
```

> **Full example data**
>
> ```tsx theme={null}
> const period = (from: string, to: string, apiCalls: number): CustomerUsageData => ({
>   from_datetime: from,
>   to_datetime: to,
>   currency: 'USD',
>   amount_cents: Math.round(apiCalls * 0.04),
>   charges_usage: [
>     {
>       units: String(apiCalls),
>       amount_cents: Math.round(apiCalls * 0.04),
>       amount_currency: 'USD',
>       charge: { nozle_id: `chg_${from}`, charge_model: 'standard' },
>       feature: { nozle_id: 'ftr_api', code: 'api_calls', name: 'API calls' },
>     },
>   ],
> })
>
> const periods: CustomerUsageData[] = [
>   period('2026-07-01T00:00:00Z', '2026-07-31T23:59:59Z', 22100),
>   period('2026-08-01T00:00:00Z', '2026-08-31T23:59:59Z', 26400),
>   period('2026-09-01T00:00:00Z', '2026-09-30T23:59:59Z', 29800),
> ]
>
> export function History() {
>   return (
>     <>
>       <UsageTrend periods={periods} />
>       <UsageTrend periods={periods} featureCode="api_calls" />
>     </>
>   )
> }
> ```

### Live data

[`useUsage({ period: 'past' })`](/sdks/react/hooks#the-hooks) 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:

```tsx theme={null}
export function LiveTrend() {
  const { data, isPending, error } = useUsage({ period: 'past', periods: 6 })
  return <UsageTrend periods={data} isLoading={isPending} error={error} />
}
```

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](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend-feature/light.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=fd2e0bd4548cfb78b35c35356e61f329)

```tsx theme={null}
export function ApiCallsTrend() {
  const { data, isPending, error } = useUsage({ period: 'past', periods: 6 })
  return <UsageTrend periods={data} featureCode="api_calls" isLoading={isPending} error={error} />
}
```

### 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](https://mintcdn.com/nozle-d78f01d8/FWVI_xhrW09Oexco/images/react/components/usage-trend-states/light.png?fit=max\&auto=format\&n=FWVI_xhrW09Oexco\&q=85\&s=a06e916bff5e7b59a8c9a6f5eef9d5ad)

```tsx theme={null}
export function TrendStates() {
  return (
    <>
      <UsageTrend isLoading />
      <UsageTrend periods={[]} />
      <UsageTrend error="Usage history could not be loaded." />
    </>
  )
}
```

## API reference

**periods** `CustomerUsageData[] | null`

The periods to chart, in any order. Empty or missing shows the empty message.

**featureCode** `string`

Charts the units of this feature instead of the amount. Bars read "29,800 api\_calls".

**isLoading** `boolean` (default: false)

Shows a loading placeholder.

**error** `Error | string | null`

Shows the message as an alert. Defaults to `null`.

**emptyMessage** `string` (default: No past usage yet.)

Shown when there are no periods.

**appearance** `Appearance`

Theme, variables and element overrides. Defaults to the provider's. See [Appearance](/sdks/react/styling).

### States

| State | What shows |
| - | - |
| `isLoading` | A skeleton placeholder with `role="status"`. |
| `error` set | The message in a `role="alert"` card, in the danger text colour. |
| No periods | `emptyMessage`. |

### Appearance

> **Element keys**
>
> `usageTrend` (root), `usageTrend__bar` (each bar).
>
> Style them with `appearance.elements`. See [Elements](/sdks/react/styling#elements).

## Related

> **[UsageBreakdown](/sdks/react/components/usage-breakdown)**
>
> This period's units and amounts.

> **[UsageDashboard](/sdks/react/components/usage-dashboard)**
>
> Usage against limits.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.