比較
啞鈴圖
用線段連接每個項目的兩個數值,凸顯兩者之間的差距。
本頁內容
啞鈴圖用來比較每個項目的兩個數值,例如比較前後變化、不同年份或不同群組。對每個標籤,各資料序列以一個點呈現,再用線段連起同一標籤下的點,讓讀者一眼看出差距的大小和方向。這種畫法比並排兩根長條更簡潔,呈現的資訊相同,刻度也可以從非零值開始。
啞鈴圖
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Pay</h3> <p class="card-description">Median by role, 2019 and 2024</p> </div> <figure class="chart" id="pay"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('pay'), { type: 'dumbbell', horizontal: true, label: 'Median pay by role in 2019 and 2024, in thousands of dollars', labels: ['Design', 'Engineering', 'Product', 'Support', 'Sales'], series: [ { name: '2019', values: [62, 84, 78, 41, 55] }, { name: '2024', values: [81, 112, 96, 52, 74] } ], format: function (value) { return '$' + value + 'k' }})})</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">Pay</h3> <p className="card-description">Median by role, 2019 and 2024</p> </div> <Chart id="pay" type="dumbbell" horizontal label="Median pay by role in 2019 and 2024, in thousands of dollars" labels={['Design', 'Engineering', 'Product', 'Support', 'Sales']} series={[ { name: '2019', values: [62, 84, 78, 41, 55] }, { name: '2024', values: [81, 112, 96, 52, 74] } ]} format={function (value) { return '$' + value + 'k' }} /></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">Pay</h3> <p class="card-description">Median by role, 2019 and 2024</p> </div> <Chart id="pay" type="dumbbell" horizontal label="Median pay by role in 2019 and 2024, in thousands of dollars" labels={['Design', 'Engineering', 'Product', 'Support', 'Sales']} series={[ { name: '2019', values: [62, 84, 78, 41, 55] }, { name: '2024', values: [81, 112, 96, 52, 74] } ]} format={function (value) { return '$' + value + 'k' }} /></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">Pay</h3> <p class="card-description">Median by role, 2019 and 2024</p> </div> <Chart id="pay" type="dumbbell" horizontal label="Median pay by role in 2019 and 2024, in thousands of dollars" :labels="['Design', 'Engineering', 'Product', 'Support', 'Sales']" :series="[ { name: '2019', values: [62, 84, 78, 41, 55] }, { name: '2024', values: [81, 112, 96, 52, 74] } ]" :format="function (value) { return '$' + value + 'k' }" /> </div></template>啞鈴圖通常採橫向版面配置,設定 horizontal: true,讓項目名稱排成易讀的清單。傳入標籤前,先按差距或其中一組數值排序,因為排列順序也會影響讀者如何解讀圖表。有三個以上的資料序列時,每個標籤會為各資料序列各畫一個點,線段則從最小值連到最大值。
#選項
| 選項 | 預設值 | |
|---|---|---|
label | 無 | 說明圖表呈現的內容和單位,作為繪圖區的無障礙名稱 |
labels | [] | 沿著刻度、環繞雷達圖或位於熱圖各欄上方的名稱 |
series | [] | 每個資料序列都有 name,並依圖表形式提供 values、value、points、ranges 或 children。可另設 category、type、low 和 high,以及圓環的 max |
horizontal | false | 讓長條、區間、啞鈴和盒鬚圖以橫向呈現 |
min, max, ticks | 自動配合資料範圍, 4 | 刻度範圍的兩端及大致的刻度數量。散佈圖的橫軸使用 xMin、xMax 和 xTicks |
format, tickFormat | 依語系 | 資料值和刻度標籤的顯示格式。散佈圖的橫軸刻度格式由 xFormat 指定 |
current | 無 | 標記為 aria-current 的資料點索引 |
legend, toggle | 有兩個資料序列時顯示, true | 是否顯示圖例,以及圖例項目是否以核取方塊呈現 |
所有圖表形式共用數值顯示、鍵盤操作、圖例、配色與刻度設定。完整的選項、CSS 類別和自訂屬性請參閱 圖表。