Đi tới nội dung
Mục
Thành phần Rastrillo

Bảng và biểu đồ

Một bảng số liệu và ba biểu đồ: biểu đồ cột, biểu đồ đường và biểu đồ thu nhỏ. Máy chủ vẽ chúng mà không cần JavaScript.

Mỗi ví dụ đều hoạt động thật, nhưng các liên kết trong đó không dẫn đến đâu. HTML hiển thị mã đánh dấu để sao chép.

data-table

Một bảng số liệu trong thẻ. Trên màn hình hẹp, cuộn thẻ sang ngang để xem mọi cột. Tiêu đề hàng luôn hiển thị.

Sắp xếp theo một con số

Xem trước
<div rst-box-head>
  <h2 id="sales-h">Doanh số theo tuần</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">Tuần</th>
        <th scope="col" rst-num aria-sort="descending">
          <a href="/sales?sort=sold&amp;dir=asc">Đã bán<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">Mục tiêu<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>Hoàn tiền</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">Tổng</th>
        <td rst-num>800</td>
        <td rst-num>2.400</td>
        <td rst-num>8</td>
      </tr>
    </tfoot>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "Tuần")
        (dict "Href" "/sales?sort=sold&dir=asc" "Label" "Đã bán" "Num" true "Sort" "descending")
        (dict "Href" "/sales?sort=target&dir=desc" "Label" "Mục tiêu" "Num" true)
        (dict "Label" "Hoàn tiền" "Num" true))
    "Foot" (list "Tổng" 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" "Doanh số theo tuần"}}

Liên kết tiêu đề cột tới danh sách đã sắp xếp, rồi đặt Sort cho cột đó. Đánh dấu các cột số bằng Num.

Dày đặc, có hàng tiêu đề cố định

Xem trước
<div rst-box-head>
  <h2 id="sales-dense-h">Doanh số theo tuần</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">Tuần</th>
        <th scope="col" rst-num>Đã bán</th>
        <th scope="col" rst-num>Mục tiêu</th>
        <th scope="col" rst-num>Hoàn tiền</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" "Tuần")
        (dict "Label" "Đã bán" "Num" true)
        (dict "Label" "Mục tiêu" "Num" true)
        (dict "Label" "Hoàn tiền" "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" "Doanh số theo tuần"}}

Dense thu gọn các hàng. Bounded giới hạn chiều cao và giữ tiêu đề luôn hiển thị khi các hàng cuộn.

Không có hàng nào khớp

Xem trước
<div rst-box-head>
  <h2 id="sales-none-h">Doanh số theo tuần</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">Tuần</th>
        <th scope="col" rst-num>Đã bán</th>
        <th scope="col" rst-num>Mục tiêu</th>
        <th scope="col" rst-num>Hoàn tiền</th>
      </tr>
    </thead>
    <tbody>
      <tr rst-table-empty>
        <td colspan="4">Không có tuần nào khớp.</td>
      </tr>
    </tbody>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "Tuần")
        (dict "Label" "Đã bán" "Num" true)
        (dict "Label" "Mục tiêu" "Num" true)
        (dict "Label" "Hoàn tiền" "Num" true))
    "Empty" "Không có tuần nào khớp."
    "ID" "sales-none"
    "Title" "Doanh số theo tuần"}}

Khi không có hàng nào, tiêu đề vẫn ở đó và Empty cho biết lý do.

chart-bar

Biểu đồ cột vẽ dưới dạng bảng: mỗi hàng có một tên, một thanh và một giá trị. Giá trị phải từ 0 trở lên.

Bốn nguồn trên cùng một thang

Xem trước
<div rst-box-head>
  <h2 id="sources-h">Vé theo nguồn</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-h" aria-describedby="sources-d">
    <p rst-chart-desc id="sources-d">Phần lớn vé bán trực tuyến, và chưa có vé nào bán qua bản tin.</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">Nguồn</th>
            <th scope="col">
              <span class="rst-sr-only">Thanh</span>
            </th>
            <th scope="col" rst-num>Vé</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">Trực tuyến</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">Quầy vé</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">Đối tác</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">Bản tin</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" "Nguồn"
    "Desc" "Phần lớn vé bán trực tuyến, và chưa có vé nào bán qua bản tin."
    "ID" "sources"
    "Measure" "Vé"
    "Points" (list
        (dict "Label" "Trực tuyến" "Value" 412)
        (dict "Label" "Quầy vé" "Value" 236)
        (dict "Label" "Đối tác" "Value" 98)
        (dict "Label" "Bản tin" "Value" 0))
    "Title" "Vé theo nguồn"}}

Mọi thanh dùng chung một thang. Để so sánh hai biểu đồ, hãy đặt cho cả hai cùng một Max.

Chưa bán được gì

Xem trước
<div rst-box-head>
  <h2 id="sources-none-h">Vé theo nguồn</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-none-h">
    <p rst-chart-empty>Chưa bán được vé nào.</p>
  </figure>
</div>
{{template "chart-bar" dict
    "Category" "Nguồn"
    "Empty" "Chưa bán được vé nào."
    "ID" "sources-none"
    "Measure" "Vé"
    "Title" "Vé theo nguồn"}}

Khi không có điểm nào, Empty thế chỗ biểu đồ.

chart-line

Một chuỗi dữ liệu dạng đường qua các điểm cách đều, kèm mọi giá trị trong bảng bên dưới.

Doanh số hằng tuần so với mục tiêu

Xem trước
<div rst-box-head>
  <h2 id="weekly-h">Doanh số hằng tuần</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="weekly-h" aria-describedby="weekly-d">
    <p rst-chart-desc id="weekly-d">Doanh số tăng gần như mỗi tuần và vượt mục tiêu 600 ở tuần 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>Mục tiêu: 600</p>
    <details rst-chart-data>
      <summary>Hiện các con số</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">Tuần</th>
              <th scope="col" rst-num>Đã bán</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">Mục tiêu</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "Tuần"
    "Desc" "Doanh số tăng gần như mỗi tuần và vượt mục tiêu 600 ở tuần 6."
    "Goal" 600
    "GoalLabel" "Mục tiêu"
    "Hover" true
    "ID" "weekly"
    "Measure" "Đã bán"
    "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" "Doanh số hằng tuần"}}

Tự viết Desc. Hãy nói đường kẻ diễn biến thế nào, không chỉ nó kết thúc ở đâu. Đặt Hover để thêm chú giải cho từng điểm.

Một tuần không có dữ liệu

Xem trước
<div rst-box-head>
  <h2 id="weekly-gap-h">Doanh số hằng tuần</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">Tuần 5 không ghi nhận doanh số nào; đường kẻ đứt ở đó.</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>Mục tiêu: 600</p>
    <details rst-chart-data>
      <summary>Hiện các con số</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">Tuần</th>
              <th scope="col" rst-num>Đã bán</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>Không có dữ liệu</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">Mục tiêu</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "Tuần"
    "Desc" "Tuần 5 không ghi nhận doanh số nào; đường kẻ đứt ở đó."
    "Goal" 600
    "GoalLabel" "Mục tiêu"
    "Hover" false
    "ID" "weekly-gap"
    "Measure" "Đã bán"
    "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" "Doanh số hằng tuần"}}

Giá trị bị thiếu làm đường kẻ bị ngắt và hiện là Không có dữ liệu trong bảng. Nó không bao giờ được vẽ thành 0.

sparkline

Một đường nhỏ bên cạnh chú thích, để thể hiện xu hướng cạnh một con số.

Đi lên, có một lần giảm

Xem trước
<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>8 tuần qua</strong> Doanh số tăng từ 120 lên 690, có một lần giảm ở tuần 4.</figcaption>
</figure>
{{template "sparkline" dict
    "Desc" "Doanh số tăng từ 120 lên 690, có một lần giảm ở tuần 4."
    "Period" "8 tuần qua"
    "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))}}

Trình đọc màn hình chỉ nhận được chú thích. Hãy nêu khoảng thời gian, và mô tả mọi lần giảm hay tăng vọt.