Charts
Metric Sparkline
A line-sized chart: the number says how much, the curve says where it is going. The colour is derived from the sign of the change, so a decline cannot be painted green.
- sparkline
- metric
- kpi
- trend
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/sparkline-001?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "sparkline-001" (Metric Sparkline) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/sparkline-001.json
Registry item: https://vibeui.ru/r/sparkline-001.json
Installs to: components/vibeui/sparkline-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A line-sized chart: the number says how much, the curve says where it is going. The colour is derived from the sign of the change, so a decline cannot be painted green.
A metric with an inline sparkline: label, large value, the period's curve and the change with an arrow. The direction is derived from the sign of delta and colours both line and arrow — colour and meaning cannot drift apart. The component is inline, so it fits a table cell. Zero dependencies, one file, its own palette.
## 3. How to use it
import { Sparkline001 } from "@/components/vibeui/sparkline-001"
<Sparkline001
label="Installs this month"
value="1,284"
delta={12.4}
values={[12, 15, 13, 19, 24, 31, 41]}
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-sparkline-001-* palette — do not swap it for your theme tokens (text-green-500, --chart-1 and the like)
- deriving the colour from the sign of delta through data-trend: a colour set independently of the value eventually lies
- the half-percent flat threshold: a 0.1 % wobble must not be coloured as growth
- the number beside the curve: a sparkline answers "where is it going", not "how much" — without the number it is useless
- vector-effect:non-scaling-stroke and preserveAspectRatio="none" — otherwise stretching makes the stroke uneven
- the aria-label on the svg carrying the value and the change
- inline-flex on the root: the metric has to sit in a line rather than break it
- the <style> block inside the component — it holds the palette and the geometry
## 6. You may change
- values — the series behind the curve
- label and value — the caption and the current figure; value is a string, so the format stays yours
- delta and unit — the change over the period and its unit
- the accent through the accent prop when one colour is wanted instead of green and red
- outer spacing through className
## 7. Rules
- The curve has no axes or labels, deliberately. A sparkline shows shape, not point values.
- Do not make it the only chart on a dashboard — shape hides scale.
- value is a string rather than a number: formatting belongs to the caller, the component does not guess digit grouping or currency.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/sparkline-001.jsonhttps://vibeui.ru/r/sparkline-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-sparkline-001-*. Кривая — SVG-путь, посчитанный из массива значений на сервере: клиентского JS нет. Направление выводится из пропа delta и попадает в data-trend, от которого зависят и цвет линии, и поворот стрелки: цвет нельзя задать вручную вразрез со знаком. Компонент inline-flex, поэтому встаёт в ячейку таблицы и в строку карточки.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { CSSProperties } from "react"
export type Sparkline001Props = {
values?: number[]
label?: string
/** Текущее значение крупно слева от кривой. */
value?: string
/** Изменение за период: положительное растёт, отрицательное падает. */
delta?: number
unit?: string
accent?: string
className?: string
style?: CSSProperties
}
// Идея компонента: график размером со строку, который стоит рядом с числом,
// а не вместо него. Число отвечает «сколько», кривая — «куда идёт», и вместе
// они занимают место одной ячейки таблицы. Цвет считается из знака изменения,
// поэтому падение нельзя случайно покрасить в зелёный.
const STYLES = `
:where([data-vibeui-block="sparkline-001"]){
--vibeui-sparkline-001-surface:oklch(1 0 0);
--vibeui-sparkline-001-surface-border:oklch(0.91 0.006 265);
--vibeui-sparkline-001-fg:oklch(0.24 0.016 265);
--vibeui-sparkline-001-muted:oklch(0.55 0.014 265);
--vibeui-sparkline-001-up:oklch(0.58 0.15 152);
--vibeui-sparkline-001-down:oklch(0.56 0.19 25);
--vibeui-sparkline-001-accent:var(--vibeui-sparkline-001-up);
--vibeui-sparkline-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Собственная подложка: строка показателя — это текст, и на тёмной
странице он обязан читаться без правки палитры проекта. */
[data-vibeui-block="sparkline-001"]{
box-sizing:border-box;padding:0.625rem 0.75rem;
background:var(--vibeui-sparkline-001-surface);
border:1px solid var(--vibeui-sparkline-001-surface-border);border-radius:0.75rem;
display:inline-flex;align-items:center;gap:0.75rem;
font-family:var(--vibeui-sparkline-001-font);color:var(--vibeui-sparkline-001-fg);
}
[data-vibeui-block="sparkline-001"][data-trend="down"]{--vibeui-sparkline-001-accent:var(--vibeui-sparkline-001-down)}
[data-vibeui-block="sparkline-001"][data-trend="flat"]{--vibeui-sparkline-001-accent:var(--vibeui-sparkline-001-muted)}
[data-vibeui-block="sparkline-001"] [data-part="text"]{display:flex;flex-direction:column;gap:0.0625rem}
[data-vibeui-block="sparkline-001"] [data-part="label"]{font-size:0.6875rem;color:var(--vibeui-sparkline-001-muted)}
[data-vibeui-block="sparkline-001"] [data-part="value"]{
font-size:1.125rem;font-weight:650;line-height:1.1;font-variant-numeric:tabular-nums;
}
[data-vibeui-block="sparkline-001"] [data-part="chart"]{display:flex;align-items:center;gap:0.4375rem}
[data-vibeui-block="sparkline-001"] svg{display:block;width:5.5rem;height:1.75rem;overflow:visible}
[data-vibeui-block="sparkline-001"] [data-part="line"]{
fill:none;stroke:var(--vibeui-sparkline-001-accent);stroke-width:1.5;
stroke-linecap:round;stroke-linejoin:round;vector-effect:non-scaling-stroke;
}
[data-vibeui-block="sparkline-001"] [data-part="dot"]{fill:var(--vibeui-sparkline-001-accent)}
[data-vibeui-block="sparkline-001"] [data-part="delta"]{
display:inline-flex;align-items:center;gap:0.1875rem;
font-size:0.75rem;font-weight:600;font-variant-numeric:tabular-nums;
color:var(--vibeui-sparkline-001-accent);
}
[data-vibeui-block="sparkline-001"] [data-part="arrow"]{
width:0.3125rem;height:0.3125rem;
border-top:1.5px solid currentColor;border-right:1.5px solid currentColor;
transform:rotate(-45deg);
}
[data-vibeui-block="sparkline-001"][data-trend="down"] [data-part="arrow"]{transform:rotate(135deg)}
[data-vibeui-block="sparkline-001"][data-trend="flat"] [data-part="arrow"]{transform:rotate(45deg) scale(0.8)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="sparkline-001"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_VALUES = [12, 15, 13, 19, 17, 24, 22, 28, 31, 29, 36, 41]
const WIDTH = 88
const HEIGHT = 28
/**
* Мини-график размером со строку: число, кривая и изменение за период.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Sparkline001({
values = DEFAULT_VALUES,
label = "Установок за месяц",
value = "1 284",
delta = 12.4,
unit = "%",
accent,
className,
style,
}: Sparkline001Props) {
const palette = {
...(accent ? { "--vibeui-sparkline-001-accent": accent } : null),
...style,
} as CSSProperties
const max = Math.max(...values)
const min = Math.min(...values)
const span = max - min || 1
const points = values.map((point, index) => ({
x: (index / Math.max(1, values.length - 1)) * WIDTH,
y: HEIGHT - ((point - min) / span) * HEIGHT,
}))
const line = points
.map((point, index) => `${index === 0 ? "M" : "L"}${point.x} ${point.y}`)
.join(" ")
const tail = points[points.length - 1]
const trend = delta > 0.5 ? "up" : delta < -0.5 ? "down" : "flat"
return (
<>
<style href="vibeui-sparkline-001" precedence="medium">
{STYLES}
</style>
<span
data-vibeui-block="sparkline-001"
data-trend={trend}
className={className}
style={palette}
>
<span data-part="text">
<span data-part="label">{label}</span>
<span data-part="value">{value}</span>
</span>
<span data-part="chart">
<svg
viewBox={`0 0 ${WIDTH} ${HEIGHT}`}
preserveAspectRatio="none"
role="img"
aria-label={`${label}: ${value}, изменение ${delta}${unit}`}
>
<path data-part="line" d={line} />
<circle data-part="dot" cx={tail.x} cy={tail.y} r={2} />
</svg>
<span data-part="delta">
<span data-part="arrow" aria-hidden="true" />
{Math.abs(delta)}
{unit}
</span>
</span>
</span>
</>
)
}