- Components
- line
Line Chart
Line and area charts for trends over time.
Demo
Traffic
Sessions per month, by device
| Month | Desktop | Mobile |
|---|---|---|
| Jan | 186 | 80 |
| Feb | 305 | 200 |
| Mar | 237 | 120 |
| Apr | 73 | 190 |
| May | 209 | 130 |
| Jun | 214 | 140 |
@php
$traffic = [
['month' => 'Jan', 'desktop' => 186, 'mobile' => 80],
['month' => 'Feb', 'desktop' => 305, 'mobile' => 200],
['month' => 'Mar', 'desktop' => 237, 'mobile' => 120],
['month' => 'Apr', 'desktop' => 73, 'mobile' => 190],
['month' => 'May', 'desktop' => 209, 'mobile' => 130],
['month' => 'Jun', 'desktop' => 214, 'mobile' => 140],
];
@endphp
<div class="w-full max-w-xl rounded-xl border border-border bg-background p-5">
<p class="font-medium text-foreground">Traffic</p>
<p class="text-sm text-muted-foreground">Sessions per month, by device</p>
<x-ui.chart type="line" :data="$traffic" index="month" label="Traffic by device" class="mt-5 h-64" :config="[
'desktop' => ['label' => 'Desktop', 'color' => 'var(--chart-1)'],
'mobile' => ['label' => 'Mobile', 'color' => 'var(--chart-2)'],
]" />
</div>
Installation
Shell
php artisan flexi:add chart
Set type="line"
or type="area"
. See
Chart
for the data model and every prop.
Area
| Month | Free | Pro |
|---|---|---|
| Jan | 2.5k | 610 |
| Feb | 3.2k | 920 |
| Mar | 3.1k | 1.2k |
| Apr | 3.7k | 1.1k |
| May | 4.4k | 1.4k |
| Jun | 4.3k | 1.7k |
| Jul | 5k | 2k |
| Aug | 5.7k | 1.8k |
| Sep | 5.6k | 2.1k |
| Oct | 6.3k | 2.4k |
| Nov | 6.9k | 2.8k |
| Dec | 6.8k | 2.6k |
@php
$downloads = collect(range(1, 12))->map(fn (int $month) => [
'month' => date('M', mktime(0, 0, 0, $month, 1)),
'free' => 1800 + $month * 420 + ($month % 3) * 260,
'pro' => 300 + $month * 190 + ($month % 4) * 120,
])->all();
@endphp
<x-ui.chart type="area" :data="$downloads" index="month" label="Downloads per month" class="h-64 w-full max-w-xl" :config="[
'free' => ['label' => 'Free', 'color' => 'var(--chart-1)'],
'pro' => ['label' => 'Pro', 'color' => 'var(--chart-2)'],
]" />
Linear curve and missing values
curve="linear"
draws straight segments. A null
value breaks the line instead of pretending the value was zero.
| Day | p95 latency |
|---|---|
| Mon | 182 ms |
| Tue | 195 ms |
| Wed | 240 ms |
| Thu | — |
| Fri | 176 ms |
| Sat | 158 ms |
| Sun | 164 ms |
@php
$uptime = [
['day' => 'Mon', 'latency' => 182],
['day' => 'Tue', 'latency' => 195],
['day' => 'Wed', 'latency' => 240],
['day' => 'Thu', 'latency' => null],
['day' => 'Fri', 'latency' => 176],
['day' => 'Sat', 'latency' => 158],
['day' => 'Sun', 'latency' => 164],
];
@endphp
{{-- `null` breaks the line: no value is made up for Thursday. --}}
<x-ui.chart type="line" curve="linear" :data="$uptime" index="day" suffix=" ms" format="number" label="API latency" class="h-56 w-full max-w-xl" :config="[
'latency' => ['label' => 'p95 latency', 'color' => 'var(--chart-2)'],
]" />
Props
Props of the <x-ui.chart.line />
layer.
| Prop | Description |
|---|---|
curve
(smooth|linear)
|
Smooth uses a monotone curve: it never overshoots the data. |
area
(boolean)
|
Fills under the line with a fading gradient. |
dots
(boolean|null)
|
Points on each value. Shown by default up to 16 categories. |
stroke-width
(number)
|
Line thickness in pixels. Defaults to 2
.
|
only
(string|array)
|
Series keys drawn by this layer. |