隨時間變化
斜率圖
從線段的斜率與交會,看出兩個時間點之間有哪些數值上升、下降或互換排序。
本頁內容
斜率圖將兩個時間點並排,為每個資料序列畫一條直線連接兩端。從線段的斜率與交會就能看出哪些數值上升、下降,以及哪些序列超越了其他序列。起點標示數值,終點標示數值與名稱,因此無須另外查看刻度或圖例。
斜率圖
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Browsers</h3> <p class="card-description">Share of sessions, 2019 and 2024</p> </div> <figure class="chart" id="share"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('share'), { type: 'slope', label: 'Share of sessions by browser in 2019 and 2024, in percent', labels: ['2019', '2024'], series: [ { name: 'Chrome', values: [58, 65] }, { name: 'Safari', values: [17, 18] }, { name: 'Firefox', values: [9, 3] }, { name: 'Edge', values: [4, 5] } ], format: function (value) { return value + '%' }})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(560) mx-auto"> <div className="card-header"> <h3 className="card-title">Browsers</h3> <p className="card-description">Share of sessions, 2019 and 2024</p> </div> <Chart id="share" type="slope" label="Share of sessions by browser in 2019 and 2024, in percent" labels={['2019', '2024']} series={[ { name: 'Chrome', values: [58, 65] }, { name: 'Safari', values: [17, 18] }, { name: 'Firefox', values: [9, 3] }, { name: 'Edge', values: [4, 5] } ]} format={function (value) { return value + '%' }} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Browsers</h3> <p class="card-description">Share of sessions, 2019 and 2024</p> </div> <Chart id="share" type="slope" label="Share of sessions by browser in 2019 and 2024, in percent" labels={['2019', '2024']} series={[ { name: 'Chrome', values: [58, 65] }, { name: 'Safari', values: [17, 18] }, { name: 'Firefox', values: [9, 3] }, { name: 'Edge', values: [4, 5] } ]} format={function (value) { return value + '%' }} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Browsers</h3> <p class="card-description">Share of sessions, 2019 and 2024</p> </div> <Chart id="share" type="slope" label="Share of sessions by browser in 2019 and 2024, in percent" :labels="['2019', '2024']" :series="[ { name: 'Chrome', values: [58, 65] }, { name: 'Safari', values: [17, 18] }, { name: 'Firefox', values: [9, 3] }, { name: 'Edge', values: [4, 5] } ]" :format="function (value) { return value + '%' }" /> </div></template>將指標移到線條上,其他線條會淡化,數值提示會列出這條線的數值。
在斜率圖中,每個資料序列整體算一個可選取的資料點。將指標移到線條上或使用方向鍵時,整條線會被選取,其他線條則會淡化。端點標籤若會重疊,圖表會將它們稍微錯開,並在上方標籤留出的空間內盡量靠近各自的線條。超過六、七個資料序列時,端點容易擁擠。可以將其餘序列合併成一條線,或改用附圖例的折線圖。
可以設定兩個以上的標籤,線條會依序連接各標籤對應的數值。標籤多時,折線圖較易閱讀。斜率圖最適合用一條直線呈現兩個時間點之間的變化。
#選項
| 選項 | 預設 | |
|---|---|---|
label | 無 | 說明圖表呈現的內容與單位,作為繪圖區的無障礙名稱 |
labels | [] | 沿刻度排列、環繞雷達圖或位於熱圖各欄上方的標籤 |
series | [] | 每個資料序列包含 name,並依圖表形式提供 values、value、points、ranges 或 children。也可指定 category、type、low、high 和圓環的 max |
min, max, ticks | 依資料調整, 4 | 刻度範圍的上下限與大致的刻度數。散佈圖的水平軸使用 xMin、xMax 和 xTicks |
format, tickFormat | 依語系 | 數值與刻度標籤的顯示格式。散佈圖的水平軸使用 xFormat |
current | 無 | 標有 aria-current 的資料點索引 |
各種圖表共用數值提示、鍵盤操作、圖例、色彩與刻度。請參閱 圖表元件 的完整選項、CSS 類別與自訂屬性。