- Components
- sparkline
Sparkline
A tiny trend line, area or bar series for KPI cards and tables.
Demo
Revenue
€48.2k
+12.4%
Active users
3,184
+4.1%
Refunds
23
-8.0%
@php
$cards = [
['label' => 'Revenue', 'value' => '€48.2k', 'change' => '+12.4%', 'up' => true, 'type' => 'area', 'color' => 'var(--chart-1)',
'data' => [18, 22, 19, 27, 25, 31, 29, 36, 34, 41, 39, 48]],
['label' => 'Active users', 'value' => '3,184', 'change' => '+4.1%', 'up' => true, 'type' => 'line', 'color' => 'var(--chart-2)',
'data' => [2810, 2890, 2860, 2950, 3010, 2980, 3070, 3120, 3090, 3150, 3184]],
['label' => 'Refunds', 'value' => '23', 'change' => '-8.0%', 'up' => false, 'type' => 'bar', 'color' => 'var(--chart-3)',
'data' => [6, 4, 7, 3, 5, 2, 4, 3, 5, 2, 3, 1]],
];
@endphp
<div class="grid w-full gap-4 sm:grid-cols-3">
@foreach ($cards as $card)
<div class="rounded-xl border border-border bg-background p-4">
<p class="text-sm text-muted-foreground">{{ $card['label'] }}</p>
<div class="mt-2 flex items-end justify-between gap-3">
<div>
<p class="text-2xl font-semibold tracking-tight text-foreground">{{ $card['value'] }}</p>
<p @class(['text-xs font-medium', 'text-success' => $card['up'], 'text-destructive' => ! $card['up']])>{{ $card['change'] }}</p>
</div>
<x-ui.sparkline :data="$card['data']" :type="$card['type']" :color="$card['color']" :label="$card['label']" class="h-10 w-24" />
</div>
</div>
@endforeach
</div>
Installation
Shell
php artisan flexi:add sparkline
Usage
Pass a list of numbers, or rows with the column to read in key
. Size it with classes.
<x-ui.sparkline :data="[12, 18, 9, 24, 31]" class="h-10 w-28" />
<x-ui.sparkline :data="$days" key="revenue" type="area" color="var(--success)" />
A line or an area follows the trend: its scale runs from the lowest to the highest value, so small moves stay visible. Bars start from zero, otherwise they would exaggerate.
Props
| Prop | Description |
|---|---|
data
(array|Collection)
|
Numbers, or rows read with key
.
|
key
(string|null)
|
Column to read in each row. Dot notation works. |
type
(line|area|bar)
|
Defaults to line
.
|
color
(string)
|
Any CSS color. Defaults to var(--chart-1)
.
|
stroke-width
(number)
|
Line thickness in pixels. Defaults to 2
.
|
dot
(boolean)
|
Marks the last value. Defaults to true
.
|
label
(string)
|
Accessible name. Screen readers hear "Revenue: from 18 to 48". |