07 · Métricas e gráficos

Sparkline

Linha mínima com degradê e ponto final com halo · desenha em loop

Mini-gráfico de tendência sem eixos para KPIs e linhas de tabela.

color neutral · primary

As duas cores abaixo usam a mesma linha; neutral em `ink`, primary em teal.
MRR$184k
Clientes1.096
.heex
<span class="text-xs text-muted">As duas cores abaixo usam a mesma linha; neutral em `ink`, primary em teal.</span>

<div class="flex flex-wrap items-center gap-2.5" style="gap:16px;margin-top:12px">
  <div class="flex w-[300px] items-center gap-4 rounded-lg border border-line bg-panel px-3.5 py-3">
    <div class="flex flex-col gap-0.5"><span class="text-xs text-muted">MRR</span><b class="text-xl tabular-nums">$184k</b></div>
    <.sparkline id="spark-mrr" color="primary" class="h-[46px] min-w-0 flex-1" values={[120, 124, 123, 131, 129, 138, 142, 150, 149, 158, 166, 170, 184]} />
  </div>
  <div class="flex w-[300px] items-center gap-4 rounded-lg border border-line bg-panel px-3.5 py-3">
    <div class="flex flex-col gap-0.5"><span class="text-xs text-muted">Clientes</span><b class="text-xl tabular-nums">1.096</b></div>
    <.sparkline id="spark-clients" class="h-[46px] min-w-0 flex-1" values={[900, 920, 915, 950, 980, 1001, 1020, 1050, 1080, 1096]} />
  </div>
</div>

Uso

<.sparkline values={@series} />

Regras

  • Sem eixos nem rótulos; o número ao lado conta a história.
  • Movimento: a linha é traçada, as barras crescem da base, o anel gira até o lugar e as células acendem por linha; repete em loop nos dois temas.

Referência da API

Todos os function components, atributos, valores e slots que este componente cobre.

The canvas's sparkline: a line with a soft fill under it, drawn on the server from a list of numbers (the highest at the top), so it renders without JavaScript. Styled only with Tailwind utilities; the line draws in once on mount (the area fades in, the end dot pops).

<.sparkline id="bb" values={[8, 12, 9, 14, 11, 16]} />
<.sparkline id="itau" values={@balances} color="primary" />

color="primary" draws it in the accent, neutral (default) in the ink. The SVG stretches to the width of its box (preserveAspectRatio="none"); the box gets its size from class/style. variant="backdrop" is the faded panel at the right of a kpi_card (it positions itself absolutely inside the card body). id names the gradient of the fill and must be unique on the page.

<.sparkline>

Attr Type Default Values / notes
id (required) :string Names the gradient of the fill, so it must be unique.
values (required) :list Numbers for the line.
color :string "neutral" neutral, primary
variant :string "inline" inline, backdrop
class :any nil

Any other HTML/phx attribute goes to the root element.