Chart Blocks
Chart compositions on the chart-card shell: a KPI metric with a headline figure, a dual-axis column/line combo, a waterfall bridge and a grid of liquid gauges. One chart in a card is chart-card plus a chart example. Comparison instead frames a two-series bar chart in a tray, with a range select swapping the bundled dataset client-side.
Preview
@props([
'heading' => 'Revenue',
'value' => '$48,200',
'trend' => '+12.5%',
'type' => 'area',
'series' => null,
'categories' => null,
'height' => 320,
])
@php
$series ??= [
[
'name' => '2024',
'data' => [18200, 22400, 21000, 27800, 31200, 29600, 35400, 38800, 36200, 42600, 45800, 48200],
],
];
$categories ??= [
__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jun'),
__('Jul'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec'),
];
// ApexCharts needs concrete colors; reference the semantic primary via its CSS variable
// so the chart still tracks the active theme (this is chart config data, not markup).
$accent = 'var(--primary-color, hsl(var(--primary)))';
// A single-series KPI needs no legend, and the entrance animation is what
// separates this composition from a plain chart card: the line draws in
// while the eye is still on the headline figure.
$options = [
'colors' => [$accent],
'chart' => [
'toolbar' => ['show' => false],
'zoom' => ['enabled' => false],
'animations' => [
'enabled' => true,
'easing' => 'easeinout',
'speed' => 800,
'animateGradually' => ['enabled' => true, 'delay' => 150],
'dynamicAnimation' => ['enabled' => true, 'speed' => 350],
],
],
'stroke' => ['curve' => 'smooth', 'width' => 2],
'dataLabels' => ['enabled' => false],
'fill' => [
'type' => 'gradient',
'gradient' => [
'shadeIntensity' => 1,
'opacityFrom' => 0.45,
'opacityTo' => 0.05,
'stops' => [0, 90, 100],
],
],
'legend' => ['show' => false],
'xaxis' => [
'categories' => $categories,
'axisBorder' => ['show' => false],
'axisTicks' => ['show' => false],
],
];
@endphp
<x-ui.chart-card
:heading="$heading"
:value="$value"
:trend="$trend"
{{ $attributes }}
>
<x-ui.chart
:type="$type"
:series="$series"
:options="$options"
:height="$height"
:label="__($heading)"
/>
</x-ui.chart-card>
Installation
php artisan ui:add blocks/chart-metric
Registry contract
Install confidence
php artisan ui:add blocks/chart-metric
writes only the generated targets below. The CLI validates each file hash before writing and
prompts before replacing local changes unless --force is used.
- Version
- 1.0.1
- License
- open
- Stability
- stable
- Contract
- v1
- Foundation
- ≥ 1.0.0
| Type | Generated target |
|---|---|
| blade | resources/views/blocks/chart-metric.blade.php |
Registry dependencies
Package dependencies
composer: jml/brok:^0.2
npm: apexcharts
Use with AI
A brief for your coding agent: what the block is, the install command, how to render it, its props and the rules. Copy it, or open a prompt about this block in an assistant.
# Brok UI block: Chart Metric (`chart-metric`)
A KPI chart card leading with a headline figure and a delta badge over an animated single-series trend line.
Brok UI is a Laravel Blade registry. `ui:add` copies this block into the app as plain Blade the app owns; it composes installed `<brok:*>` primitives and semantic design tokens.
## Install
```bash
php artisan ui:add blocks/chart-metric
```
## Render it
```blade
<x-blocks.chart-metric type="area" />
```
## Props
- `heading` (string, default `Revenue`) — Muted KPI label above the value.
- `value` (string, default `$48,200`) — Headline figure.
- `trend` (string|null, default `+12.5%`) — Delta badge; a leading minus tones it destructive.
- `type` (area|line|bar, default `area`) (variant) — Chart type behind the figure.
- `series` (array|null, default `null`) — ApexCharts series; null renders a twelve-month sample.
- `categories` (array|null, default `null`) — X-axis categories; null renders month names.
- `height` (int, default `320`) — Chart height in pixels.
## Use when
- A dashboard tile must lead with one number and show how it got there.
- A single measure is tracked over a period and the shape of the line matters more than its exact values.
## Avoid when
- Several series are compared; use a chart card with a legend instead.
- No history exists behind the number; use the stat primitive.
## Rules
- Render the installed block with `<x-blocks.chart-metric />` and pass data through its props; edit the copied file only for structural changes.
- Keep the semantic design tokens (`bg-background`, `text-muted-foreground`); never swap in raw colour utilities.
- Keep the `data-slot` attributes and the logical (start/end) spacing so the markup still mirrors under `dir="rtl"`.
## Links
- Docs: https://brokui.dev/blocks/chart-metric
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/chart-metric.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
Guidance
Use when
- A dashboard tile must lead with one number and show how it got there.
- A single measure is tracked over a period and the shape of the line matters more than its exact values.
Avoid when
- Several series are compared; use a chart card with a legend instead.
- No history exists behind the number; use the stat primitive.
Anti-patterns
- Do not replace semantic props with conflicting utility classes.
- Do not remove labels, focus styles, or state attributes.
- Anatomy
Usage
Render the block as a component, passing data where useful:
<x-blocks.chart-metric />
The controls above the preview are props on this composition. What you picked reads:
Built from primitives
This block composes installed <brok:*> primitives and semantic design
tokens only — it does not reimplement any primitive. Re-theme it (light, dark, admin, customer) by
editing CSS variables; flip the preview to RTL to confirm it mirrors.
Source
The exact, editable file ui:add writes
into your app. The preview above renders this same source — there are no preview-only blocks.
@props([
'heading' => 'Revenue',
'value' => '$48,200',
'trend' => '+12.5%',
'type' => 'area',
'series' => null,
'categories' => null,
'height' => 320,
])
@php
$series ??= [
[
'name' => '2024',
'data' => [18200, 22400, 21000, 27800, 31200, 29600, 35400, 38800, 36200, 42600, 45800, 48200],
],
];
$categories ??= [
__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jun'),
__('Jul'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec'),
];
// ApexCharts needs concrete colors; reference the semantic primary via its CSS variable
// so the chart still tracks the active theme (this is chart config data, not markup).
$accent = 'var(--primary-color, hsl(var(--primary)))';
// A single-series KPI needs no legend, and the entrance animation is what
// separates this composition from a plain chart card: the line draws in
// while the eye is still on the headline figure.
$options = [
'colors' => [$accent],
'chart' => [
'toolbar' => ['show' => false],
'zoom' => ['enabled' => false],
'animations' => [
'enabled' => true,
'easing' => 'easeinout',
'speed' => 800,
'animateGradually' => ['enabled' => true, 'delay' => 150],
'dynamicAnimation' => ['enabled' => true, 'speed' => 350],
],
],
'stroke' => ['curve' => 'smooth', 'width' => 2],
'dataLabels' => ['enabled' => false],
'fill' => [
'type' => 'gradient',
'gradient' => [
'shadeIntensity' => 1,
'opacityFrom' => 0.45,
'opacityTo' => 0.05,
'stops' => [0, 90, 100],
],
],
'legend' => ['show' => false],
'xaxis' => [
'categories' => $categories,
'axisBorder' => ['show' => false],
'axisTicks' => ['show' => false],
],
];
@endphp
<x-ui.chart-card
:heading="$heading"
:value="$value"
:trend="$trend"
{{ $attributes }}
>
<x-ui.chart
:type="$type"
:series="$series"
:options="$options"
:height="$height"
:label="__($heading)"
/>
</x-ui.chart-card>
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.0.1 - Status
- Stable
- License
-
open - Deprecation
- Not deprecated
- Contract
-
v1 - Foundation
-
≥ 1.0.0