07 · Métricas e gráficos

Stat

stat_group card/sunken/linha · stat_item tone default/accent · size default/sm · unit · delta · meta · sparkline

Números curtos lado a lado, cada um com o rótulo em cima e uma divisória entre eles, dentro de um card ou numa linha. Para resumos de pedido, cabeçalhos de página e faixas de indicadores.

Os números sobem, a linha se desenha e a variação aparece

Faturamento R$ 184.320 12,4% vs. outubro
Pedidos 1.096 8,1% vs. outubro
Cancelamentos 23 0,4 pt caiu
Ticket médio R$ 168 0% estável
.heex
<.stat_group animated>
  <.stat_item
    icon="wallet"
    label="Faturamento"
    value="R$ 184.320"
    change="12,4%"
    note="vs. outubro"
    sparkline={[0, 3.5, 2.3, 6.1, 5.2, 8.7, 11, 9.8, 13.3, 15.1, 17.7, 22]}
  />
  <.stat_item
    icon="cart"
    label="Pedidos"
    value="1.096"
    change="8,1%"
    note="vs. outubro"
    sparkline={[0.6, 3, 0, 4.8, 7.7, 5.9, 9.5, 13.1, 11.3, 14.9, 18.4, 22]}
  />
  <.stat_item
    icon="alert"
    label="Cancelamentos"
    value="23"
    change="0,4 pt"
    trend="down"
    note="caiu"
    sparkline={[20.4, 17.3, 22, 15.7, 12.6, 14.1, 7.9, 11, 6.3, 3.1, 4.7, 0]}
    sparkline_tone="pos"
  />
  <.stat_item
    icon="tag"
    label="Ticket médio"
    value="R$ 168"
    change="0%"
    trend="flat"
    note="estável"
    sparkline={[0, 7.3, 3.7, 3.7, 11, 7.3, 14.7, 11, 14.7, 18.3, 14.7, 22]}
    sparkline_tone="mut"
  />
</.stat_group>

stat_group · card e variant

card · variant=default
Subtotal R$ 3.240
Desconto − R$ 120
Frete R$ 0 grátis acima de R$ 300
Total R$ 3.120
variant=sunken
Estoque 1.284un
Reservado 96un
Giro 18dias
Cobertura 42dias
card={false} · numa linha, separados por divisória
Abertas 12
Vencidas 3 1
Pagas no mês R$ 48,2 mil 9%
.heex
<div class="flex flex-col gap-[18px]">
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">card · variant=default</span>
    <.stat_group>
      <.stat_item label="Subtotal" value="R$ 3.240" />
      <.stat_item label="Desconto" value="− R$ 120" />
      <.stat_item label="Frete" value="R$ 0" note="grátis acima de R$ 300" />
      <.stat_item label="Total" value="R$ 3.120" tone="accent" />
    </.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">variant=sunken</span>
    <.stat_group variant="sunken">
      <.stat_item label="Estoque" value="1.284" unit="un" />
      <.stat_item label="Reservado" value="96" unit="un" />
      <.stat_item label="Giro" value="18" unit="dias" />
      <.stat_item label="Cobertura" value="42" unit="dias" tone="accent" />
    </.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted" phx-no-curly-interpolation>card={false} · numa linha, separados por divisória</span>
    <.stat_group card={false}>
      <.stat_item label="Abertas" value="12" />
      <.stat_item label="Vencidas" value="3" change="1" change_tone="neg" />
      <.stat_item label="Pagas no mês" value="R$ 48,2 mil" change="9%" />
    </.stat_group>
  </div>
</div>

stat_item · tone × size · unit

tone=default
Clientes 1.096
tone=accent
Total R$ 3.120
size=sm
Pagamento Boleto
unit
Prazo médio 18dias
.heex
<div class="grid w-full grid-cols-2 gap-x-[18px] gap-y-4">
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">tone=default</span>
    <.stat_group><.stat_item label="Clientes" value="1.096" /></.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">tone=accent</span>
    <.stat_group><.stat_item label="Total" value="R$ 3.120" tone="accent" /></.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">size=sm</span>
    <.stat_group><.stat_item label="Pagamento" value="Boleto" size="sm" /></.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">unit</span>
    <.stat_group><.stat_item label="Prazo médio" value="18" unit="dias" /></.stat_group>
  </div>
</div>

Variação, meta e tendência

delta subindo (bom)
Recebido hoje R$ 12.480 18% vs. ontem
delta subindo (ruim)
Em atraso R$ 3.210 6% vs. semana passada
meta
Meta do mês R$ 184 mil 74% de R$ 250 mil · faltam 10 dias
sparkline
Pedidos / dia 48 últimos 12 dias
.heex
<div class="grid w-full grid-cols-2 gap-x-[18px] gap-y-4">
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">delta subindo (bom)</span>
    <.stat_group>
      <.stat_item label="Recebido hoje" value="R$ 12.480" change="18%" note="vs. ontem" />
    </.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">delta subindo (ruim)</span>
    <.stat_group>
      <.stat_item
        label="Em atraso"
        value="R$ 3.210"
        change="6%"
        change_tone="neg"
        note="vs. semana passada"
      />
    </.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">meta</span>
    <.stat_group>
      <.stat_item
        label="Meta do mês"
        value="R$ 184 mil"
        meter={74}
        note="74% de R$ 250 mil · faltam 10 dias"
      />
    </.stat_group>
  </div>
  <div class="flex flex-col gap-2 w-full">
    <span class="font-mono text-xs text-muted">sparkline</span>
    <.stat_group>
      <.stat_item
        label="Pedidos / dia"
        value="48"
        note="últimos 12 dias"
        sparkline={[0.6, 3, 0, 4.8, 7.7, 5.9, 9.5, 13.1, 11.3, 14.9, 18.4, 22]}
      />
    </.stat_group>
  </div>
</div>

No contexto: resumo do pedido

Pedido #2491 Pago
Itens 14
Subtotal R$ 1.320,40
Desconto − R$ 35,50
Total R$ 1.284,90
.heex
<div class="flex w-full max-w-[640px] flex-col gap-3.5 rounded-lg border border-line bg-panel px-5 py-[18px]">
  <div class="flex flex-wrap items-center justify-between gap-2.5">
    <b class="text-[15px]">Pedido #2491</b>
    <.badge canvas dot color="success">Pago</.badge>
  </div>
  <.stat_group variant="sunken">
    <.stat_item label="Itens" value="14" />
    <.stat_item label="Subtotal" value="R$ 1.320,40" />
    <.stat_item label="Desconto" value="− R$ 35,50" />
    <.stat_item label="Total" value="R$ 1.284,90" tone="accent" />
  </.stat_group>
</div>

Uso

<.stat_group>
  <.stat_item label="Subtotal" value="R$ 3.240" />
  <.stat_item label="Desconto" value="− R$ 120" />
  <.stat_item label="Total" value="R$ 3.120" tone="accent" />
</.stat_group>

<.stat_group variant="sunken">
  <.stat_item label="Estoque" value="1.284" unit="un" />
  <.stat_item label="Giro" value="18" unit="dias" />
</.stat_group>

<.stat_item label="Faturamento" value="R$ 184.320" icon="huge-wallet-01"
  delta="12,4%" trend="up" hint="vs. outubro" spark={@serie} />

Regras

  • Use de 2 a 5 itens por grupo; acima disso, prefira KpiCard.
  • O valor já chega formatado (R$, pontos de milhar, vírgula); unit é o sufixo pequeno (un, dias, %).
  • tone="accent" só no número que fecha a conta (o total).
  • delta é verde quando o movimento é bom e vermelho quando é ruim, não pela direção: cancelamento caindo é verde.
  • Movimento: os números sobem e aparecem, a sparkline se desenha e a variação entra; repete em loop nos dois temas.

Referência da API

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

Short figures side by side: the label over the number, a divider between them, inside a card, a sunken strip or a bare row.

<.stat_group>
  <.stat_item label="Subtotal" value="R$ 3.240" />
  <.stat_item label="Desconto" value="− R$ 120" />
  <.stat_item label="Total" value="R$ 3.120" tone="accent" />
</.stat_group>

<.stat_group animated>
  <.stat_item
    icon="huge-wallet"
    label="Faturamento"
    value="R$ 184.320"
    change="12,4%"
    note="vs. outubro"
    sparkline={[0, 3.5, 2.3, 6.1, 5.2, 8.7, 11, 9.8, 13.3, 15.1, 17.7, 22]}
  />
</.stat_group>

The vitrine names work as aliases: delta (change), hint (note), goal (meter), spark (sparkline) and delta_tone (change_tone, with good/bad).

stat_item/1 carries everything a figure can say: a unit (dias, un), a change with its direction (trend) and tone (good or bad news), a note under the figure, a goal meter and a sparkline (a list of numbers). tone="accent" highlights the total of a strip and size="sm" sets a word (Boleto) instead of a number. stat_group draws the strip: card (the default) frames it, card={false} leaves a bare row, variant="sunken" fills it with the sunken background, and animated adds the canvas loop: the figures rise, the lines draw and the changes pop in. Styled only with Tailwind utilities; the group exposes data-variant, data-card and data-animated, which the items read with group-data-[...]/stats: variants.

badge puts a small caps badge beside the label (badge_tone is a LedgerUI.Color name, primary by default; badge_dot adds a dot, "live" pulses it: <.stat_item badge="Ao vivo" badge_dot="live" .../>). For free content use <:label_badge>, which replaces the text. prefix is a small raised mark before the figure (R$). Without them the markup does not change.

value_id sets the id of the figure element (to update or test it). The default slot is free content after the figure and its charts; <:footer> is a last line (a link, a caption).

<.stat_item>

Attr Type Default Values / notes
label (required) :string
value (required) :string The figure, already formatted.
unit :string nil A smaller faint suffix beside the figure.
icon :string nil An icon name before the label.
tone :string "default" default, accent
size :string "md" default, md, sm - sm sets a word instead of a number.
delta :string nil The variation, already formatted (12,4%).
change :string nil Alias of delta.
trend :string "up" up, down, flat - The arrow of delta.
delta_tone :string nil nil, good, bad, pos, neg, flat - Good (good/pos) or bad (bad/neg) news; by default good, or flat when trend is flat.
change_tone :string nil nil, pos, neg, flat - Alias of delta_tone.
hint :string nil The faint line under the figure (vs. outubro).
note :string nil Alias of hint.
goal :integer nil Goal progress, 0..100: draws the bar.
meter :integer nil Alias of goal.
goal_label :string nil The line under the goal bar.
spark :list nil Numbers of a trend (at least two); the last one is the dot.
sparkline :list nil Alias of spark.
spark_tone :string "accent" accent, acc, pos, muted, mut
sparkline_tone :string nil nil, accent, acc, pos, muted, mut - Alias of spark_tone.
badge :string nil A badge beside the label (Ao vivo).
badge_tone :string "primary" current, dark, error, info, light, lime, mono, neutral, primary, secondary, success, warning, white - The colour of the badge.
badge_dot :any false A dot in the badge; "live" makes it pulse.
prefix :string nil A small raised mark before the figure (R$).
value_id :string nil The id of the figure element.
class :any nil

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

Slots:

  • <:footer> - A last line of the item (a link, a caption), after everything else.
  • <:inner_block> - Free content under the figure, its changes and its charts.
  • <:label_badge> - Free content for the badge beside the label (instead of badge).

<.stat_group>

Attr Type Default Values / notes
card :boolean true Frames the strip; false leaves a bare row.
variant :string "default" default, sunken
animated :boolean false The canvas loop: figures rise, lines draw, changes pop in.
class :any nil

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

Slots:

  • <:inner_block> (required)