スパークライン
文中やテーブルの行、統計指標に収まる、細い線1本の推移グラフ。
このページの内容
スパークラインは、推移を細い線1本で示す小さなグラフです。統計指標の数値の下や、テーブルの列、文中など、関連するテキストのそばに置けます。線を描くインライン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>#線の描画
グラフはviewBox="0 0 100 100"とpreserveAspectRatio="none"を指定した<svg class="sparkline-plot">で描画します。幅と高さがともに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の円はグラフの伸縮で楕円になるため、HTMLで円形を保ちます。同じ100 × 100の座標系で、最後の点の座標を--xと--yに指定し、点の中心を配置します。背後の面と同じ色のリングで点の周囲の線を抜き、線が点で終わるように見せます。スパークラインの領域内には点の半分が収まる余白を確保し、後ろの単語に点が近づきすぎないようにします。
#塗りつぶしと基準線
sparkline-areaは、同じ点を通り、下端に沿って閉じた<path>(V100 H0 Z)です。線と同じ色で淡く塗り、下に向かって透明にします。線の前に配置すると、その上に線が描画されます。
sparkline-baselineは、平均値、目標値、前期の値などの高さで、0から100まで引く細い点線の<line>です。推移を示す線より控えめに表示します。上の統計指標の例のように、基準線が何を示すかをスパークラインの隣に記載します。
#文中で使う
スパークラインの幅は4em、高さは大文字とほぼ同じ.75emです。中心を周囲の大文字の高さの中央にそろえるため、単語のように行内に収まります。ページ上でもカード内でも、インク色の背景面でも、周囲のテキスト色を使います。
文中で使う
<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"を指定し、「1日あたり31,000から61,000に増加」など、推移を説明するaria-labelを付けます。グラフ全体が1つの画像として扱われます。 - 文中や統計指標のように、隣のテキストや数値ですでに推移が伝わる場合は、読み上げの重複を防ぐため、
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 | 点の横位置です。描画の最後の点の x 座標を 0〜100 で指定します。指定先:sparkline-dot | |
--y | 点の縦位置です。描画の最後の点の y 座標を、上端の 0 から下端の 100 までの範囲で指定します。指定先:sparkline-dot |