Ir al contenido
Secciones
Componentes de Rastrillo

Tablas y gráficos

Una tabla de cifras y tres gráficos: uno de barras, uno de líneas y un minigráfico. El servidor los dibuja sin JavaScript.

Cada ejemplo funciona de verdad, pero sus enlaces no llevan a ninguna parte. HTML muestra el marcado para copiar.

data-table

Una tabla de cifras en una tarjeta. En una pantalla estrecha, desplaza la tarjeta en horizontal para ver todas las columnas. Los encabezados de fila siguen a la vista.

Ordenada por un número

Vista previa
<div rst-box-head>
  <h2 id="sales-h">Ventas 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">Vendidas<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" "Vendidas" "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" "Ventas por semana"}}

Enlaza el encabezado de una columna a la lista ordenada y luego pon Sort en esa columna. Marca las columnas de números con Num.

Densa, con el encabezado fijo

Vista previa
<div rst-box-head>
  <h2 id="sales-dense-h">Ventas 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>Vendidas</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" "Vendidas" "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" "Ventas por semana"}}

Dense ajusta las filas. Bounded limita la altura y mantiene el encabezado a la vista mientras se desplazan las filas.

Ninguna fila coincide

Vista previa
<div rst-box-head>
  <h2 id="sales-none-h">Ventas 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>Vendidas</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">Ninguna semana coincide.</td>
      </tr>
    </tbody>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "Semana")
        (dict "Label" "Vendidas" "Num" true)
        (dict "Label" "Objetivo" "Num" true)
        (dict "Label" "Reembolsos" "Num" true))
    "Empty" "Ninguna semana coincide."
    "ID" "sales-none"
    "Title" "Ventas por semana"}}

Sin filas, el encabezado se queda y Empty explica por qué.

chart-bar

Un gráfico de barras dibujado como tabla: un nombre, una barra y un valor en cada fila. Los valores deben ser cero o más.

Cuatro orígenes en una misma escala

Vista previa
<div rst-box-head>
  <h2 id="sources-h">Entradas por origen</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-h" aria-describedby="sources-d">
    <p rst-chart-desc id="sources-d">La mayoría de las entradas se vendieron en línea y, por el boletín, ninguna todavía.</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">Origen</th>
            <th scope="col">
              <span class="rst-sr-only">Barra</span>
            </th>
            <th scope="col" rst-num>Entradas</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">En línea</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">Taquilla</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">Socios</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">Boletín</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" "Origen"
    "Desc" "La mayoría de las entradas se vendieron en línea y, por el boletín, ninguna todavía."
    "ID" "sources"
    "Measure" "Entradas"
    "Points" (list
        (dict "Label" "En línea" "Value" 412)
        (dict "Label" "Taquilla" "Value" 236)
        (dict "Label" "Socios" "Value" 98)
        (dict "Label" "Boletín" "Value" 0))
    "Title" "Entradas por origen"}}

Todas las barras comparten una escala. Para comparar dos gráficos, da a ambos el mismo Max.

Nada vendido todavía

Vista previa
<div rst-box-head>
  <h2 id="sources-none-h">Entradas por origen</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-none-h">
    <p rst-chart-empty>Todavía no se ha vendido ninguna entrada.</p>
  </figure>
</div>
{{template "chart-bar" dict
    "Category" "Origen"
    "Empty" "Todavía no se ha vendido ninguna entrada."
    "ID" "sources-none"
    "Measure" "Entradas"
    "Title" "Entradas por origen"}}

Sin puntos, Empty ocupa el lugar del gráfico.

chart-line

Una serie como línea sobre puntos espaciados por igual, con cada valor en una tabla debajo.

Ventas semanales frente a un objetivo

Vista previa
<div rst-box-head>
  <h2 id="weekly-h">Ventas semanales</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="weekly-h" aria-describedby="weekly-d">
    <p rst-chart-desc id="weekly-d">Las ventas subieron casi todas las semanas y superaron el objetivo de 600 en la 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 las cifras</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>Vendidas</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" "Las ventas subieron casi todas las semanas y superaron el objetivo de 600 en la semana 6."
    "Goal" 600
    "GoalLabel" "Objetivo"
    "Hover" true
    "ID" "weekly"
    "Measure" "Vendidas"
    "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" "Ventas semanales"}}

Escribe Desc tú mismo. Di qué hace la línea, no solo dónde termina. Pon Hover para añadir una descripción emergente a cada punto.

Una semana sin datos

Vista previa
<div rst-box-head>
  <h2 id="weekly-gap-h">Ventas semanales</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">No se registraron ventas en la semana 5; la línea se corta ahí.</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 las cifras</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>Vendidas</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>Sin datos</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" "No se registraron ventas en la semana 5; la línea se corta ahí."
    "Goal" 600
    "GoalLabel" "Objetivo"
    "Hover" false
    "ID" "weekly-gap"
    "Measure" "Vendidas"
    "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" "Ventas semanales"}}

Un valor que falta corta la línea y en la tabla aparece como Sin datos. Nunca se dibuja como 0.

sparkline

Una línea pequeña junto a su leyenda, para mostrar una tendencia al lado de un número.

En subida, con una caída

Vista previa
<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> Las ventas subieron de 120 a 690, con una bajada en la semana 4.</figcaption>
</figure>
{{template "sparkline" dict
    "Desc" "Las ventas subieron de 120 a 690, con una bajada en la 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))}}

La leyenda es todo lo que recibe un lector de pantalla. Indica el periodo y describe cualquier caída o pico.