--- import DefaultLayout from '@shared/layouts/DefaultLayout.astro' import CaptureScript from '@shared/components/CaptureScript.astro' import Card from '@ui/Card.astro' import CardBody from '@ui/CardBody.astro' import CardTitle from '@ui/CardTitle.astro' import CardSubtitle from '@ui/CardSubtitle.astro' import DocsLink from '@ui/DocsLink.astro' import Badge from '@ui/Badge.astro' import Sparkline from '@ui/Sparkline.astro' import type { SparklineType } from '@ui/Sparkline.astro' import site from '@data/site.json' import { ucFirst } from '@shared/lib/string-format' const colors = Object.keys(site.colors) const metrics: { name: string; value: string; color: string; type: SparklineType; fill?: string; values: string }[] = [ { name: 'Revenue', value: '$12.4k', color: 'success', type: 'line', fill: 'auto', values: '5,6,7,6,8,9,10' }, { name: 'Orders', value: '1,352', color: 'primary', type: 'bar', values: '3,4,2,6,5,8,7' }, { name: 'Errors', value: '31', color: 'danger', type: 'bar', values: '2,3,5,4,8,13,21' }, { name: 'CPU usage', value: '72%', color: 'info', type: 'line', values: '40,55,50,70,65,80,72' }, ] const progress = [ { label: 'Completion 10%', value: 10, color: 'danger' }, { label: 'Completion 50%', value: 50, color: 'warning' }, { label: 'Completion 72%', value: 72, color: 'primary' }, { label: 'Completion 100%', value: 100, color: 'success' }, ] ---
Line Add data-bs-toggle="sparkline" and a comma-separated data-bs-values list.
Area with spot Use data-bs-fill="auto" for a tinted area and data-bs-spot to mark the last, min or max value.
Bars Set data-bs-type="bar". Tune the gap and rounding with data-bs-bar-gap and data-bs-bar-radius.
Signed bars Negative values hang below a zero line in --tblr-sparkline-negative, red by default; the line uses --tblr-sparkline-zero.
Win/loss Set data-bs-type="tristate": every value is a full bar up, down or a tick on the zero line, whatever its size.
Threshold Set data-bs-threshold to draw a guide line at a value. Bars below it take the negative color.
Circle Use data-bs-type="circle" with a single value as a share of data-bs-max, sparkline-square for a round box and data-bs-label="auto" for the percentage in the middle.
{progress.map((item) => )} {progress.map((item) => )}
Disabled Add sparkline-disabled to grey out a chart, for a series that is off or data that is stale.
Colors The chart uses currentColor, so any text-{'{color}'} utility themes it.
{colors.map((color) => )}
Fixed range Set data-bs-min and data-bs-max so several charts share the same scale.
Sizes Add sparkline-sm or sparkline-lg; for a custom box override --tblr-sparkline-width and --tblr-sparkline-height.
Stroke width Change --tblr-sparkline-stroke-width and --tblr-sparkline-spot-size in SVG units.
Update from JavaScript Call update(values) on the instance. It writes data-bs-values back, tweens the chart for data-bs-animation milliseconds and fires updated.bs.sparkline.
In a table A sparkline sits inline with text, so it works in table cells and stat rows.
{ metrics.map((metric) => ( )) }
Metric Value Trend
{metric.name} {metric.value}