迷你趨勢線
用一條細線呈現趨勢,小巧到能放進句子、表格列或統計數值元件。
本頁內容
迷你趨勢線用一條細線呈現趨勢,能就近放在說明文字所在的位置,例如 統計數值 元件中的數字下方、表格 的欄位內,或句子中。它是行內 SVG,會伸展以填滿可用空間,線條則維持 1.5px 的筆畫寬度,並沿用周圍的文字色。圓點標示最新數值,圖形無論怎麼拉伸,圓點都保持正圓。整個元件無須腳本。
迷你趨勢線
<div class="card max-w(320) mx-auto"> <div class="stat"> <p class="stat-label">Requests per day</p> <div class="stat-row"> <p class="stat-value">61,240</p> <p class="stat-delta stat-delta-up"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(-90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(-90 8 8)" /> </svg>12.4% </p> </div> <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> <p class="stat-description">The last 14 days; the dotted line is their average</p> </div></div>import ArrowUpIcon from '@master/icons-react/native/16/soft/arrow-up'<div className="card max-w(320) mx-auto"> <div className="stat"> <p className="stat-label">Requests per day</p> <div className="stat-row"> <p className="stat-value">61,240</p> <p className="stat-delta stat-delta-up"><ArrowUpIcon className="icon" />12.4%</p> </div> <span className="sparkline" style={{ '--sparkline-width': '100%', '--sparkline-height': '2.5rem' } as React.CSSProperties} aria-hidden="true"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line className="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span> </span> <p className="stat-description">The last 14 days; the dotted line is their average</p> </div></div><script> import ArrowUpIcon from '@master/icons-svelte/native/16/soft/arrow-up'</script><div class="card max-w(320) mx-auto"> <div class="stat"> <p class="stat-label">Requests per day</p> <div class="stat-row"> <p class="stat-value">61,240</p> <p class="stat-delta stat-delta-up"><ArrowUpIcon class="icon" />12.4%</p> </div> <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> <p class="stat-description">The last 14 days; the dotted line is their average</p> </div></div><script setup>import ArrowUpIcon from '@master/icons-vue/native/16/soft/arrow-up'</script><template> <div class="card max-w(320) mx-auto"> <div class="stat"> <p class="stat-label">Requests per day</p> <div class="stat-row"> <p class="stat-value">61,240</p> <p class="stat-delta stat-delta-up"><ArrowUpIcon class="icon" />12.4%</p> </div> <span class="sparkline" style="--sparkline-width: 100%; --sparkline-height: 2.5rem" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-area" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0 V100 H0 Z" /><line class="sparkline-baseline" x1="0" y1="55.5" x2="100" y2="55.5" /><path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> <p class="stat-description">The last 14 days; the dotted line is their average</p> </div> </div></template>#線條的繪製方式
圖形由 <svg class="sparkline-plot"> 繪製,並設定 viewBox="0 0 100 100" 和 preserveAspectRatio="none"。這會建立一個寬、高各為 100 單位的方框,再將它拉伸至迷你趨勢線的尺寸。只要在這個方框內設定一次座標,同一條線就能放進句子或卡片。
- 水平方向,第一個點位於 0,最後一個點位於 100,相鄰兩點的間距都相同。有 14 個數值時,每隔 100 / 13 單位放一個點。
- 垂直方向依 SVG 的座標慣例,頂端是 0,底端是 100。將最低值對應到 100、最高值對應到 0。比較多條迷你趨勢線時,也可以自行設定尺度。
sparkline-line 是穿過各點的 <path>(或 <polyline>)。筆畫寬度不會隨方框拉伸(vector-effect: non-scaling-stroke),因此在任何尺寸下都維持 1.5px,接合處與端點也都採圓角。
迷你趨勢線呈現的是走勢。下表的每條線都以各專案自己的最低值和最高值作為尺度,因此要看各專案的走勢,可以看線條。要比較數值大小,則看旁邊的數字。
#最新數值
sparkline-dot 是用 HTML 繪製的小圓點,可避免 SVG 圓形隨圖形拉伸而變成橢圓。沿用寬、高各為 100 的座標系統,以最後一個點的座標設定 --x 和 --y,將圓點的中心放在該處。圓點外圍有一圈與背景同色的外框,遮住靠近圓點的線段,讓線條在圓點邊緣收尾。迷你趨勢線會在自己的方框內留出半個圓點的空間,避免圓點貼到後方的文字。
#填色區域與基準線
sparkline-area 是穿過相同座標點、沿底端閉合的 <path>(V100 H0 Z)。填色沿用線條色的淡色調,向下逐漸淡出。將它放在線條之前,讓線條繪製在填色上方。
sparkline-baseline 是一條極細的點線,以 <line> 在平均值、目標值或上一期數值所對應的高度從 0 畫到 100。基準線比趨勢線低調,並由迷你趨勢線旁的文字說明它代表什麼,如上方的統計數值範例所示。
#句中顯示
迷你趨勢線寬 4em、高 .75em,高度約等於大寫字母。它的垂直中心與旁邊大寫字母的中心對齊,因此能像單字一樣排在同一行。不論放在頁面、卡片或採用 ink 配色的區塊上,都沿用所在位置的文字色。
句中顯示
<p class="m(0) max-w(440) mx-auto fg-text-body"> Requests rose all fortnight <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" /> </svg> </span> to 128 ms.</p><p className="m(0) max-w(440) mx-auto fg-text-body"> Requests rose all fortnight <span className="sparkline" aria-hidden="true"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span> </span> to 61,000 a day, while latency fell <span className="sparkline" aria-hidden="true"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" /> </svg> </span> to 128 ms.</p><p class="m(0) max-w(440) mx-auto fg-text-body"> Requests rose all fortnight <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" /> </svg> </span> to 128 ms.</p><template> <p class="m(0) max-w(440) mx-auto fg-text-body"> Requests rose all fortnight <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> to 61,000 a day, while latency fell <span class="sparkline" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 0 L7.69 11.1 L15.38 3.7 L23.08 20.4 L30.77 25.9 L38.46 22.2 L46.15 42.6 L53.85 55.6 L61.54 50 L69.23 66.7 L76.92 75.9 L84.62 72.2 L92.31 85.2 L100 100" /> </svg> </span> to 128 ms. </p></template>#表格中顯示
在迷你趨勢線上設定 --sparkline-width 和 --sparkline-height,也可以在表格等容器上設定一次,讓其中所有迷你趨勢線套用相同尺寸。若要像上方的統計數值範例一樣讓迷你趨勢線填滿卡片寬度,請設定 --sparkline-width: 100%。
表格中顯示
<div class="sheet overflow-hidden max-w(480) mx-auto"> <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Last 14 days</th> <th class="table-heading table-numeric" scope="col">Today</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising steadily"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">61,240</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Falling"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> </td> <td class="table-cell table-numeric">36,018</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising slowly"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">16,420</td> </tr> </tbody> </table></div><div className="sheet overflow-hidden max-w(480) mx-auto"> <table className="table table-compact" style={{ '--sparkline-width': '5rem', '--sparkline-height': '1rem' } as React.CSSProperties}> <thead> <tr className="table-row"> <th className="table-heading" scope="col">Project</th> <th className="table-heading" scope="col">Last 14 days</th> <th className="table-heading table-numeric" scope="col">Today</th> </tr> </thead> <tbody> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Atlas</th> <td className="table-cell"> <span className="sparkline" role="img" aria-label="Rising steadily"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span> </span> </td> <td className="table-cell table-numeric">61,240</td> </tr> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Borealis</th> <td className="table-cell"> <span className="sparkline" role="img" aria-label="Falling"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '100' } as React.CSSProperties}></span> </span> </td> <td className="table-cell table-numeric">36,018</td> </tr> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Cirrus</th> <td className="table-cell"> <span className="sparkline" role="img" aria-label="Rising slowly"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span> </span> </td> <td className="table-cell table-numeric">16,420</td> </tr> </tbody> </table></div><div class="sheet overflow-hidden max-w(480) mx-auto"> <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Last 14 days</th> <th class="table-heading table-numeric" scope="col">Today</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising steadily"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">61,240</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Falling"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> </td> <td class="table-cell table-numeric">36,018</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising slowly"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">16,420</td> </tr> </tbody> </table></div><template> <div class="sheet overflow-hidden max-w(480) mx-auto"> <table class="table table-compact" style="--sparkline-width: 5rem; --sparkline-height: 1rem"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Last 14 days</th> <th class="table-heading table-numeric" scope="col">Today</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising steadily"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 90 L15.38 93.3 L23.08 76.7 L30.77 83.3 L38.46 66.7 L46.15 56.7 L53.85 63.3 L61.54 46.7 L69.23 30 L76.92 40 L84.62 20 L92.31 10 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">61,240</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Falling"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 5.9 L7.69 17.6 L15.38 0 L23.08 23.5 L30.77 35.3 L38.46 29.4 L46.15 52.9 L53.85 41.2 L61.54 70.6 L69.23 58.8 L76.92 82.4 L84.62 76.5 L92.31 94.1 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> </td> <td class="table-cell table-numeric">36,018</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"> <span class="sparkline" role="img" aria-label="Rising slowly"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 100 L7.69 79.2 L15.38 91.7 L23.08 58.3 L30.77 66.7 L38.46 45.8 L46.15 54.2 L53.85 33.3 L61.54 41.7 L69.23 20.8 L76.92 29.2 L84.62 12.5 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> </td> <td class="table-cell table-numeric">16,420</td> </tr> </tbody> </table> </div></template>#狀態色
sparkline-success、sparkline-warning 和 sparkline-danger 會以狀態色繪製線條和圓點。走勢上升也可能代表錯誤增加,此時應用危險色繪製上升線。請在旁邊的文字也傳達相同狀態時才使用這些類別,讓使用者也能透過文字辨識狀態。
狀態色
<p class="m(0) max-w(440) mx-auto fg-text-body"> After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> and now takes 3.2 seconds.</p><p className="m(0) max-w(440) mx-auto fg-text-body"> After the fix, errors fell by half <span className="sparkline sparkline-success" aria-hidden="true"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '100' } as React.CSSProperties}></span> </span> to 18 an hour. Checkout got slower <span className="sparkline sparkline-danger" aria-hidden="true"> <svg className="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path className="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" /> </svg><span className="sparkline-dot" style={{ '--x': '100', '--y': '0' } as React.CSSProperties}></span> </span> and now takes 3.2 seconds.</p><p class="m(0) max-w(440) mx-auto fg-text-body"> After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> and now takes 3.2 seconds.</p><template> <p class="m(0) max-w(440) mx-auto fg-text-body"> After the fix, errors fell by half <span class="sparkline sparkline-success" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 9.1 L7.69 0 L15.38 15.2 L23.08 6.1 L30.77 21.2 L38.46 39.4 L46.15 60.6 L53.85 72.7 L61.54 78.8 L69.23 87.9 L76.92 81.8 L84.62 90.9 L92.31 97 L100 100" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 100"></span> </span> to 18 an hour. Checkout got slower <span class="sparkline sparkline-danger" aria-hidden="true"> <svg class="sparkline-plot" viewBox="0 0 100 100" preserveAspectRatio="none"> <path class="sparkline-line" d="M0 91.7 L7.69 100 L15.38 83.3 L23.08 91.7 L30.77 75 L38.46 83.3 L46.15 66.7 L53.85 58.3 L61.54 66.7 L69.23 41.7 L76.92 33.3 L84.62 25 L92.31 16.7 L100 0" /> </svg><span class="sparkline-dot" style="--x: 100; --y: 0"></span> </span> and now takes 3.2 seconds. </p></template>#無障礙
- 如果旁邊的文字沒有描述走勢,請為迷你趨勢線加上
role="img",並以aria-label描述走勢,例如「每日從 31,000 增至 61,000」。這樣輔助技術就會把其中的圖形視為一張圖片。 - 如果旁邊的文字或數字已說明走勢,例如在句子或統計數值元件中,請用
aria-hidden="true"隱藏迷你趨勢線,以免重複朗讀。 - 在強制色彩模式下,線條和圓點會沿用文字色,填色區域則會省略。
#瀏覽器無法在 SVG 上套用遮罩時
填色區域透過套用在 SVG 形狀上的 CSS 遮罩逐漸淡出。若瀏覽器無法為 SVG 形狀套用遮罩,整個區域就會均勻填上同一種線條色的淡色調。
#類別
| 類別 | 說明 |
|---|---|
sparkline | 圖形填滿寬 4em、高 .75em 的方框,底緣對齊大寫字母高度的中點。請加上 role="img",並以 aria-label 描述趨勢。若旁邊已列出數值,則使用 aria-hidden="true" |
sparkline-success | 以成功狀態色呈現正向趨勢,並在旁邊以文字說明搭配 sparkline 使用 |
sparkline-warning | 以警示色標出值得留意的趨勢,旁邊的文字也會提示搭配 sparkline 使用 |
sparkline-danger | 不利的趨勢使用危險狀態的前景色,旁邊的文字也會說明搭配 sparkline 使用 |
sparkline-plot | 圖樣使用設有 viewBox="0 0 100 100" 和 preserveAspectRatio="none" 的 SVG,拉伸至迷你趨勢圖的範圍。筆畫可超出邊界 |
sparkline-line | 趨勢線寬 1.5px,沿用周圍的文字色,接合處與端點皆為圓弧。圖形縮放時,線寬維持不變 |
sparkline-area | 沿用折線的各點,沿底部封閉成填色區域。使用線條顏色的淺色調,向下漸淡。請放在折線之前 |
sparkline-baseline | 用極細的點線標示基準、平均值或目標,降低相對於趨勢線的視覺比重 |
sparkline-dot | 最新值以 5px 圓點標示,由 --x 和 --y 定位。圖形拉伸時仍維持正圓,外圍以背景色描邊,將圓點和線條隔開 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--sparkline-width | 迷你趨勢圖的寬度,預設為 4em。可設在表格等容器上,統一調整容器內所有迷你趨勢圖的寬度 | |
--sparkline-height | 迷你趨勢圖的高度,預設為 .75em,約等於大寫字母的高度。也可在容器上設定 | |
--sparkline-stroke | 1.5px | 線條寬度 |
--sparkline-dot | 5px | 最新數值標記圓點的大小 |
--x | 圓點的水平位置,範圍為 0 到 100,取繪圖中最後一點的 x 座標設定於 sparkline-dot | |
--y | 圓點的垂直位置,頂端為 0,底端為 100,取繪圖中最後一點的 y 座標設定於 sparkline-dot |