跳到內容
欄目
Rastrillo 組件

表同圖表

一個數字表同三種圖表:棒形圖、線圖同迷你走勢圖。伺服器唔使 JavaScript 就畫到。

每個例子都真係用得,不過入面啲連結唔會帶你去邊度。 HTML 顯示可以複製嘅標記。

data-table

張卡入面嘅數字表。喺窄嘅畫面上,左右碌張卡就睇到每一欄。行標題會一直留喺度。

按數字排序

預覽
<div rst-box-head>
  <h2 id="sales-h">按週計嘅銷量</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">週</th>
        <th scope="col" rst-num aria-sort="descending">
          <a href="/sales?sort=sold&amp;dir=asc">賣出<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">目標<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>退款</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">總數</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" "週")
        (dict "Href" "/sales?sort=sold&dir=asc" "Label" "賣出" "Num" true "Sort" "descending")
        (dict "Href" "/sales?sort=target&dir=desc" "Label" "目標" "Num" true)
        (dict "Label" "退款" "Num" true))
    "Foot" (list "總數" 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" "按週計嘅銷量"}}

將欄標題連去排好序嘅列表,再喺嗰欄設 Sort。數字欄用 Num 標明。

密集,表頭固定

預覽
<div rst-box-head>
  <h2 id="sales-dense-h">按週計嘅銷量</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">週</th>
        <th scope="col" rst-num>賣出</th>
        <th scope="col" rst-num>目標</th>
        <th scope="col" rst-num>退款</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" "週")
        (dict "Label" "賣出" "Num" true)
        (dict "Label" "目標" "Num" true)
        (dict "Label" "退款" "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" "按週計嘅銷量"}}

Dense 令每行密啲。Bounded 限住高度,碌行嗰陣表頭一直睇到。

冇行符合

預覽
<div rst-box-head>
  <h2 id="sales-none-h">按週計嘅銷量</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">週</th>
        <th scope="col" rst-num>賣出</th>
        <th scope="col" rst-num>目標</th>
        <th scope="col" rst-num>退款</th>
      </tr>
    </thead>
    <tbody>
      <tr rst-table-empty>
        <td colspan="4">冇符合嘅週。</td>
      </tr>
    </tbody>
  </table>
</div>
{{template "data-table" dict
    "Columns" (list
        (dict "Label" "週")
        (dict "Label" "賣出" "Num" true)
        (dict "Label" "目標" "Num" true)
        (dict "Label" "退款" "Num" true))
    "Empty" "冇符合嘅週。"
    "ID" "sales-none"
    "Title" "按週計嘅銷量"}}

冇行嘅時候,表頭照樣喺度,Empty 講點解。

chart-bar

用表嚟畫嘅棒形圖:每行有一個名、一條棒同一個數值。數值一定要係零或者以上。

四個來源,同一個刻度

預覽
<div rst-box-head>
  <h2 id="sources-h">按來源劃分嘅門票</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-h" aria-describedby="sources-d">
    <p rst-chart-desc id="sources-d">大部分門票都係網上賣出,經電子報賣出嘅暫時一張都冇。</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">來源</th>
            <th scope="col">
              <span class="rst-sr-only">條形</span>
            </th>
            <th scope="col" rst-num>門票</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">網上</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">售票處</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">合作夥伴</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">電子報</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" "來源"
    "Desc" "大部分門票都係網上賣出,經電子報賣出嘅暫時一張都冇。"
    "ID" "sources"
    "Measure" "門票"
    "Points" (list
        (dict "Label" "網上" "Value" 412)
        (dict "Label" "售票處" "Value" 236)
        (dict "Label" "合作夥伴" "Value" 98)
        (dict "Label" "電子報" "Value" 0))
    "Title" "按來源劃分嘅門票"}}

每條棒都用同一個刻度。想比較兩幅圖,就俾佢哋同一個 Max。

仲未賣出任何嘢

預覽
<div rst-box-head>
  <h2 id="sources-none-h">按來源劃分嘅門票</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="sources-none-h">
    <p rst-chart-empty>仲未賣出任何門票。</p>
  </figure>
</div>
{{template "chart-bar" dict
    "Category" "來源"
    "Empty" "仲未賣出任何門票。"
    "ID" "sources-none"
    "Measure" "門票"
    "Title" "按來源劃分嘅門票"}}

冇數據點嘅時候,Empty 會頂替幅圖。

chart-line

一組數據用線畫喺等距嘅點上面,每個數值都列喺下面張表度。

每週銷量對比目標

預覽
<div rst-box-head>
  <h2 id="weekly-h">每週銷量</h2>
</div>
<div rst-card>
  <figure rst-chart aria-labelledby="weekly-h" aria-describedby="weekly-d">
    <p rst-chart-desc id="weekly-d">銷量差唔多每週都升,第 6 週超過咗 600 嘅目標。</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>目標:600</p>
    <details rst-chart-data>
      <summary>顯示數字</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">週</th>
              <th scope="col" rst-num>賣出</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">目標</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "週"
    "Desc" "銷量差唔多每週都升,第 6 週超過咗 600 嘅目標。"
    "Goal" 600
    "GoalLabel" "目標"
    "Hover" true
    "ID" "weekly"
    "Measure" "賣出"
    "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" "每週銷量"}}

Desc 要自己寫。講條線點樣走,唔好淨係講佢喺邊度收尾。設 Hover 就會喺每個點加提示。

有一週冇數據

預覽
<div rst-box-head>
  <h2 id="weekly-gap-h">每週銷量</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">第 5 週冇銷售紀錄;條線喺嗰度斷開。</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>目標:600</p>
    <details rst-chart-data>
      <summary>顯示數字</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">週</th>
              <th scope="col" rst-num>賣出</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>冇數據</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">目標</th>
              <td rst-num>600</td>
            </tr>
          </tfoot>
        </table>
      </div>
    </details>
  </figure>
</div>
{{template "chart-line" dict
    "Category" "週"
    "Desc" "第 5 週冇銷售紀錄;條線喺嗰度斷開。"
    "Goal" 600
    "GoalLabel" "目標"
    "Hover" false
    "ID" "weekly-gap"
    "Measure" "賣出"
    "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" "每週銷量"}}

冇數值嘅地方條線會斷開,表入面顯示「冇數據」。永遠唔會畫成 0。

sparkline

喺說明文字旁邊嘅一條細線,用嚟喺數字隔籬顯示走勢。

上升,中間跌咗一下

預覽
<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 週</strong> 銷量由 120 升到 690,中間第 4 週跌咗一下。</figcaption>
</figure>
{{template "sparkline" dict
    "Desc" "銷量由 120 升到 690,中間第 4 週跌咗一下。"
    "Period" "最近 8 週"
    "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))}}

讀屏器淨係讀到說明文字。寫明時段,有跌或者急升都要講。