导航

v2.1.0
比较

哑铃图

用线段连接每个对象的两个数值,突出两者的差距。

本页内容

哑铃图用于比较每个对象的两个数值,例如变化前后、两个年份或两个群体的数据。同一标签下,每个数据系列用一个点表示,各点由线段连接,让读者一眼看出差距有多大、哪个值更高。它用占用面积小得多的点和线传达与两根并排柱条相同的信息,数值轴也无需从零开始。

哑铃图

<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
horizontalfalse让条形、区间、哑铃和箱体横向排列
min, max, ticks自动适配, 4坐标轴的两端及大致的刻度数。散点图的横轴使用 xMin、xMax 和 xTicks
format, tickFormat由区域设置决定数值和刻度的显示格式。散点图的横轴使用 xFormat
current无标记了 aria-current 的数据点索引
legend, toggle有两个数据系列时显示图例, true是否显示图例,以及图例项是否为复选框

所有图表类型共用相同的读数显示、按键操作、图例、颜色和刻度。有关这些行为以及所有选项、类和自定义属性,请参阅 图表。