Ir para o conteúdo
Secções
Componentes do Rastrillo

Tabelas e gráficos

Uma tabela de valores e três gráficos: um de barras, um de linhas e um minigráfico. O servidor desenha-os sem JavaScript.

Cada exemplo funciona de verdade, mas as suas ligações não levam a lado nenhum. HTML mostra a marcação para copiar.

data-table

Uma tabela de valores num cartão. Num ecrã estreito, desloque o cartão na horizontal para ver todas as colunas. Os cabeçalhos das linhas ficam à vista.

Ordenada por um número

Pré-visualização
<div rst-box-head>
  <h2 id="sales-h">Vendas por semana</h2>
</div>
<div rst-card rst-table-scroll="" tabindex="0" role="region" aria-labelledby="sales-h">
  <table rst-table="" aria-labelledby="sales-h">
    <thead>
      <tr>
        <th scope="col">Semana</th>
        <th scope="col" rst-num aria-sort="descending">
          <a href="/sales?sort=sold&amp;dir=asc">Vendidos<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></a>
        </th>
        <th scope="col" rst-num>
          <a href="/sales?sort=target&amp;dir=desc">Objetivo<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></a>
        </th>
        <th scope="col" rst-num>Reembolsos</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">3</th>
        <td rst-num>260</td>
        <td rst-num>600</td>
        <td rst-num>5</td>
      </tr>
      <tr>
        <th scope="row">4</th>
        <td rst-num>240</td>
        <td rst-num>600</td>
        <td rst-num>1</td>
      </tr>
      <tr>
        <th scope="row">2</th>
        <td rst-num>180</td>
        <td rst-num>600</td>
        <td rst-num>0</td>
      </tr>
      <tr>
        <th scope="row">1</th>
        <td rst-num>120</td>
        <td rst-num>600</td>
        <td rst-num>2</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <th scope="row">Total</th>
        <td rst-num>800</td>
        <td rst-num>2400</td>
        <td rst-num>8</td>
      </tr>
    </tfoot>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "Semana")
        (dict "Href" "/sales?sort=sold&dir=asc" "Label" "Vendidos" "Num" true "Sort" "descending")
        (dict "Href" "/sales?sort=target&dir=desc" "Label" "Objetivo" "Num" true)
        (dict "Label" "Reembolsos" "Num" true))
    "Foot" (list "Total" 800 2400 8)
    "ID" "sales"
    "Rows" (list (list 3 260 600 5) (list 4 240 600 1) (list 2 180 600 0) (list 1 120 600 2))
    "Title" "Vendas por semana"}}

Ligue o cabeçalho de uma coluna à lista ordenada e defina Sort nessa coluna. Marque as colunas de números com Num.

Densa, com cabeçalho fixo

Pré-visualização
<div rst-box-head>
  <h2 id="sales-dense-h">Vendas por semana</h2>
</div>
<div rst-card rst-table-scroll="bounded" tabindex="0" role="region" aria-labelledby="sales-dense-h">
  <table rst-table="dense" aria-labelledby="sales-dense-h">
    <thead>
      <tr>
        <th scope="col">Semana</th>
        <th scope="col" rst-num>Vendidos</th>
        <th scope="col" rst-num>Objetivo</th>
        <th scope="col" rst-num>Reembolsos</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">1</th>
        <td rst-num>120</td>
        <td rst-num>600</td>
        <td rst-num>2</td>
      </tr>
      <tr>
        <th scope="row">2</th>
        <td rst-num>180</td>
        <td rst-num>600</td>
        <td rst-num>0</td>
      </tr>
      <tr>
        <th scope="row">3</th>
        <td rst-num>260</td>
        <td rst-num>600</td>
        <td rst-num>5</td>
      </tr>
      <tr>
        <th scope="row">4</th>
        <td rst-num>240</td>
        <td rst-num>600</td>
        <td rst-num>1</td>
      </tr>
      <tr>
        <th scope="row">5</th>
        <td rst-num>390</td>
        <td rst-num>600</td>
        <td rst-num>3</td>
      </tr>
      <tr>
        <th scope="row">6</th>
        <td rst-num>610</td>
        <td rst-num>600</td>
        <td rst-num>4</td>
      </tr>
      <tr>
        <th scope="row">7</th>
        <td rst-num>650</td>
        <td rst-num>600</td>
        <td rst-num>0</td>
      </tr>
      <tr>
        <th scope="row">8</th>
        <td rst-num>690</td>
        <td rst-num>600</td>
        <td rst-num>2</td>
      </tr>
    </tbody>
  </table>
</div>
{{template "data-table" dict
    "Bounded" true
    "Columns" (list
        (dict "Label" "Semana")
        (dict "Label" "Vendidos" "Num" true)
        (dict "Label" "Objetivo" "Num" true)
        (dict "Label" "Reembolsos" "Num" true))
    "Dense" true
    "ID" "sales-dense"
    "Rows" (list (list 1 120 600 2) (list 2 180 600 0) (list 3 260 600 5) (list 4 240 600 1) (list 5 390 600 3) (list 6 610 600 4) (list 7 650 600 0) (list 8 690 600 2))
    "Title" "Vendas por semana"}}

Dense aperta as linhas. Bounded limita a altura e mantém o cabeçalho à vista enquanto as linhas deslizam.

Nenhuma linha corresponde

Pré-visualização
<div rst-box-head>
  <h2 id="sales-none-h">Vendas por semana</h2>
</div>
<div rst-card rst-table-scroll="" tabindex="0" role="region" aria-labelledby="sales-none-h">
  <table rst-table="" aria-labelledby="sales-none-h">
    <thead>
      <tr>
        <th scope="col">Semana</th>
        <th scope="col" rst-num>Vendidos</th>
        <th scope="col" rst-num>Objetivo</th>
        <th scope="col" rst-num>Reembolsos</th>
      </tr>
    </thead>
    <tbody>
      <tr rst-table-empty>
        <td colspan="4">Nenhuma semana corresponde.</td>
      </tr>
    </tbody>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "Semana")
        (dict "Label" "Vendidos" "Num" true)
        (dict "Label" "Objetivo" "Num" true)
        (dict "Label" "Reembolsos" "Num" true))
    "Empty" "Nenhuma semana corresponde."
    "ID" "sales-none"
    "Title" "Vendas por semana"}}

Sem linhas, o cabeçalho fica e Empty diz porquê.

chart-bar

Um gráfico de barras desenhado como tabela: um nome, uma barra e um valor em cada linha. Os valores têm de ser zero ou mais.

Quatro origens na mesma escala

Pré-visualização
<div rst-box-head>
  <h2 id="sources-h">Bilhetes por origem</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-h" aria-describedby="sources-d">
    <p rst-chart-desc id="sources-d">A maioria dos bilhetes foi vendida online e, pela newsletter, nenhum até agora.</p>
    <div rst-table-scroll tabindex="0" role="region" aria-labelledby="sources-h">
      <table rst-table="bars" aria-labelledby="sources-h" aria-describedby="sources-d">
        <thead>
          <tr>
            <th scope="col">Origem</th>
            <th scope="col">
              <span class="rst-sr-only">Barra</span>
            </th>
            <th scope="col" rst-num>Bilhetes</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">Online</th>
            <td rst-table-bar>
              <svg viewBox="0 0 1000 1" preserveAspectRatio="none" aria-hidden="true" focusable="false"><rect width="1000" height="1"/></svg>
            </td>
            <td rst-num>412</td>
          </tr>
          <tr>
            <th scope="row">Bilheteira</th>
            <td rst-table-bar>
              <svg viewBox="0 0 1000 1" preserveAspectRatio="none" aria-hidden="true" focusable="false"><rect width="572.8" height="1"/></svg>
            </td>
            <td rst-num>236</td>
          </tr>
          <tr>
            <th scope="row">Parceiros</th>
            <td rst-table-bar>
              <svg viewBox="0 0 1000 1" preserveAspectRatio="none" aria-hidden="true" focusable="false"><rect width="237.9" height="1"/></svg>
            </td>
            <td rst-num>98</td>
          </tr>
          <tr>
            <th scope="row">Newsletter</th>
            <td rst-table-bar>
              <svg viewBox="0 0 1000 1" preserveAspectRatio="none" aria-hidden="true" focusable="false"><rect width="0" height="1"/></svg>
            </td>
            <td rst-num>0</td>
          </tr>
        </tbody>
      </table>
    </div>
  </figure>
</div>
{{template "chart-bar" dict
    "Category" "Origem"
    "Desc" "A maioria dos bilhetes foi vendida online e, pela newsletter, nenhum até agora."
    "ID" "sources"
    "Measure" "Bilhetes"
    "Points" (list
        (dict "Label" "Online" "Value" 412)
        (dict "Label" "Bilheteira" "Value" 236)
        (dict "Label" "Parceiros" "Value" 98)
        (dict "Label" "Newsletter" "Value" 0))
    "Title" "Bilhetes por origem"}}

Todas as barras partilham uma escala. Para comparar dois gráficos, dê a ambos o mesmo Max.

Ainda nada vendido

Pré-visualização
<div rst-box-head>
  <h2 id="sources-none-h">Bilhetes por origem</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-none-h">
    <p rst-chart-empty>Ainda não foi vendido nenhum bilhete.</p>
  </figure>
</div>
{{template "chart-bar" dict
    "Category" "Origem"
    "Empty" "Ainda não foi vendido nenhum bilhete."
    "ID" "sources-none"
    "Measure" "Bilhetes"
    "Title" "Bilhetes por origem"}}

Sem pontos, Empty ocupa o lugar do gráfico.

chart-line

Uma série como linha sobre pontos igualmente espaçados, com cada valor numa tabela por baixo.

Vendas semanais face a um objetivo

Pré-visualização
<div rst-box-head>
  <h2 id="weekly-h">Vendas semanais</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="weekly-h" aria-describedby="weekly-d">
    <p rst-chart-desc id="weekly-d">As vendas subiram quase todas as semanas e ultrapassaram o objetivo de 600 na semana 6.</p>
    <div rst-chart-plot aria-hidden="true">
      <div rst-chart-y>
        <span>800</span><span>600</span><span>400</span><span>200</span><span>0</span>
      </div>
      <svg viewBox="0 0 1000 1000" preserveAspectRatio="none" focusable="false"><path rst-chart-grid d="M0 0H1000M0 250H1000M0 500H1000M0 750H1000"/><path rst-chart-base d="M0 1000H1000"/><path rst-chart-goal d="M0 250H1000"/><polyline rst-chart-line points="0,850 142.9,775 285.7,675 428.6,700 571.4,512.5 714.3,237.5 857.1,187.5 1000,137.5"/><path rst-chart-ring d="M1000 137.5h0"/><path rst-chart-dot d="M1000 137.5h0"/></svg>
      <div rst-chart-hits>
        <span title="1: 120"></span><span title="2: 180"></span><span title="3: 260"></span><span title="4: 240"></span><span title="5: 390"></span><span title="6: 610"></span><span title="7: 650"></span><span title="8: 690"></span>
      </div>
      <div rst-chart-x>
        <span rst-chart-keep>1</span><span>2</span><span rst-chart-keep>3</span><span>4</span><span rst-chart-keep>5</span><span>6</span><span>7</span><span rst-chart-keep>8</span>
      </div>
    </div>
    <p rst-chart-key>Objetivo: 600</p>
    <details rst-chart-data>
      <summary>Mostrar os números</summary>
      <div rst-table-scroll tabindex="0" role="region" aria-labelledby="weekly-h">
        <table rst-table="dense" aria-labelledby="weekly-h">
          <thead>
            <tr>
              <th scope="col">Semana</th>
              <th scope="col" rst-num>Vendidos</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th scope="row">1</th>
              <td rst-num>120</td>
            </tr>
            <tr>
              <th scope="row">2</th>
              <td rst-num>180</td>
            </tr>
            <tr>
              <th scope="row">3</th>
              <td rst-num>260</td>
            </tr>
            <tr>
              <th scope="row">4</th>
              <td rst-num>240</td>
            </tr>
            <tr>
              <th scope="row">5</th>
              <td rst-num>390</td>
            </tr>
            <tr>
              <th scope="row">6</th>
              <td rst-num>610</td>
            </tr>
            <tr>
              <th scope="row">7</th>
              <td rst-num>650</td>
            </tr>
            <tr>
              <th scope="row">8</th>
              <td rst-num>690</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <th scope="row">Objetivo</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "Semana"
    "Desc" "As vendas subiram quase todas as semanas e ultrapassaram o objetivo de 600 na semana 6."
    "Goal" 600
    "GoalLabel" "Objetivo"
    "Hover" true
    "ID" "weekly"
    "Measure" "Vendidos"
    "Points" (list
        (dict "Label" 1 "Value" 120)
        (dict "Label" 2 "Value" 180)
        (dict "Label" 3 "Value" 260)
        (dict "Label" 4 "Value" 240)
        (dict "Label" 5 "Value" 390)
        (dict "Label" 6 "Value" 610)
        (dict "Label" 7 "Value" 650)
        (dict "Label" 8 "Value" 690))
    "Title" "Vendas semanais"}}

Escreva o Desc você mesmo. Diga o que a linha faz, não só onde acaba. Defina Hover para acrescentar uma dica a cada ponto.

Uma semana sem dados

Pré-visualização
<div rst-box-head>
  <h2 id="weekly-gap-h">Vendas semanais</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="weekly-gap-h" aria-describedby="weekly-gap-d">
    <p rst-chart-desc id="weekly-gap-d">Não se registaram vendas na semana 5; a linha interrompe-se aí.</p>
    <div rst-chart-plot aria-hidden="true">
      <div rst-chart-y>
        <span>800</span><span>600</span><span>400</span><span>200</span><span>0</span>
      </div>
      <svg viewBox="0 0 1000 1000" preserveAspectRatio="none" focusable="false"><path rst-chart-grid d="M0 0H1000M0 250H1000M0 500H1000M0 750H1000"/><path rst-chart-base d="M0 1000H1000"/><path rst-chart-goal d="M0 250H1000"/><polyline rst-chart-line points="0,850 142.9,775 285.7,675 428.6,700"/><polyline rst-chart-line points="714.3,237.5 857.1,187.5 1000,137.5"/><path rst-chart-ring d="M1000 137.5h0"/><path rst-chart-dot d="M1000 137.5h0"/></svg>
      <div rst-chart-x>
        <span rst-chart-keep>1</span><span>2</span><span rst-chart-keep>3</span><span>4</span><span rst-chart-keep>5</span><span>6</span><span>7</span><span rst-chart-keep>8</span>
      </div>
    </div>
    <p rst-chart-key>Objetivo: 600</p>
    <details rst-chart-data>
      <summary>Mostrar os números</summary>
      <div rst-table-scroll tabindex="0" role="region" aria-labelledby="weekly-gap-h">
        <table rst-table="dense" aria-labelledby="weekly-gap-h">
          <thead>
            <tr>
              <th scope="col">Semana</th>
              <th scope="col" rst-num>Vendidos</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th scope="row">1</th>
              <td rst-num>120</td>
            </tr>
            <tr>
              <th scope="row">2</th>
              <td rst-num>180</td>
            </tr>
            <tr>
              <th scope="row">3</th>
              <td rst-num>260</td>
            </tr>
            <tr>
              <th scope="row">4</th>
              <td rst-num>240</td>
            </tr>
            <tr>
              <th scope="row">5</th>
              <td rst-num>Sem dados</td>
            </tr>
            <tr>
              <th scope="row">6</th>
              <td rst-num>610</td>
            </tr>
            <tr>
              <th scope="row">7</th>
              <td rst-num>650</td>
            </tr>
            <tr>
              <th scope="row">8</th>
              <td rst-num>690</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <th scope="row">Objetivo</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "Semana"
    "Desc" "Não se registaram vendas na semana 5; a linha interrompe-se aí."
    "Goal" 600
    "GoalLabel" "Objetivo"
    "Hover" false
    "ID" "weekly-gap"
    "Measure" "Vendidos"
    "Points" (list
        (dict "Label" 1 "Value" 120)
        (dict "Label" 2 "Value" 180)
        (dict "Label" 3 "Value" 260)
        (dict "Label" 4 "Value" 240)
        (dict "Label" 5 "Missing" true "Value" 390)
        (dict "Label" 6 "Value" 610)
        (dict "Label" 7 "Value" 650)
        (dict "Label" 8 "Value" 690))
    "Title" "Vendas semanais"}}

Um valor em falta interrompe a linha e aparece na tabela como Sem dados. Nunca é desenhado como 0.

sparkline

Uma linha pequena ao lado da legenda, para mostrar uma tendência junto a um número.

A subir, com uma descida

Pré-visualização
<figure rst-spark>
  <svg viewBox="0 0 100 24" preserveAspectRatio="none" aria-hidden="true" focusable="false"><polyline rst-chart-line points="0,24 14.3,21.5 28.6,18.1 42.9,18.9 57.1,12.6 71.4,3.4 85.7,1.7 100,0"/><path rst-chart-ring d="M100 0h0"/><path rst-chart-dot d="M100 0h0"/></svg>
  <figcaption>
    <strong>Últimas 8 semanas</strong> As vendas subiram de 120 para 690, com uma descida na semana 4.</figcaption>
</figure>
{{template "sparkline" dict
    "Desc" "As vendas subiram de 120 para 690, com uma descida na semana 4."
    "Period" "Últimas 8 semanas"
    "Points" (list
        (dict "Label" 1 "Value" 120)
        (dict "Label" 2 "Value" 180)
        (dict "Label" 3 "Value" 260)
        (dict "Label" 4 "Value" 240)
        (dict "Label" 5 "Value" 390)
        (dict "Label" 6 "Value" 610)
        (dict "Label" 7 "Value" 650)
        (dict "Label" 8 "Value" 690))}}

A legenda é tudo o que um leitor de ecrã recebe. Indique o período e descreva qualquer descida ou pico.