Navigation

v2.1.0
Comparison

Dumbbell chart

Two values of each thing joined by a stem, so the gap between them is the mark.

On this page

A dumbbell compares two values of each thing: before and after, one year and another, one group and the next. Each series is a dot, and a stem joins the dots of one label, so what a reader sees first is the gap and which way it runs. It says the same as two bars side by side with a fraction of the ink, and it does not need to start at zero.

Dumbbell chart

<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>

A dumbbell usually runs across, horizontal: true, so the names read as a list. Sort the labels by the gap or by one of the values before giving them: the order is part of what the chart says. With three series or more each label has a dot for each and the stem runs from the lowest to the highest.

#Options

OptionDefault
labelnoneWhat the chart shows and in what unit: the plot's accessible name
labels[]The names along the scale, around a radar or over a heatmap's columns
series[]Each with a name and what its form reads: values, a value, points, ranges or children; optionally a category, a type, low and high, and a ring's max
horizontalfalseBars, ranges, dumbbells and boxes run across
min, max, ticksfit, 4The ends of the scale and about how many steps mark it; xMin, xMax and xTicks for a scatter's scale across
format, tickFormatthe locale'sHow a value and a tick are written; xFormat for a scatter's scale across
currentnoneThe index of the point marked aria-current
legend, togglewith two series, trueWhether a legend is written, and whether its entries are checkboxes

The readout, the keys, the legend, the colors and the scale are the same in every form: Chart holds them, with every option, class and custom property.