Appearance
Charts > Dumbbell plot
A dumbbell plot uses two markers connected by a line to represent the comparison or change in values between two distinct data points, often illustrating the before-and-after or the difference between two categories.
The Chart
Other compatible charts
From % to % (+NaN%)
Download example CSV
Copy HTML
Playground
Animation
Duration of animation in ms
Style
Color of dot
Color of dot
Color of line between dots
Show value labels next to dots
Height for each row
vue
<template>
<DumbbellPlot :data="data" @hover="setTooltip" />
<OTTooltip :info="tooltip">
<div>
From {{ tooltip.data.x1 }}% to {{ tooltip.data.x2 }}% ({{
tooltip.data.x1 > tooltip.data.x2 ? "-" : "+"
}}{{ Math.abs(tooltip.data.x1 - tooltip.data.x2) }}%)
</div>
</OTTooltip>
</template>
<script setup>
import useTooltip from "@/functions/useTooltip.js";
const [tooltip, setTooltip] = useTooltip();
</script>Component API
The dumbbell plot shows a difference in value between two categories. It is built with SVG and d3. The horizontal position of the dumbbells animates when the data changes, using d3 transition.
Data
js
[
{ id: "Category 1", name: "Category 1", x1: 20, x2: 40 },
{ id: "Category 2", name: "Category 2", x1: 80, x2: 30 },
...
]Props
| Name | Default | Description | Type |
|---|---|---|---|
| data | "[]" | The dataset | Array |
| colorLine | "#9CA3AF" | The color for the line between dots | String |
| colorDot1 | "#F59E0B" | The color for the dot of category 1 | String |
| colorDot2 | "#3B82F6" | The color for the dot of category 2 | String |
| colorBg | "#f3f4f6" | The background color for highlighted row | String |
| colorAxis | "#6B7280" | The color of the x axis | String |
| xAxisDomain | "[0, 100]" | The min and max value for x axis | Array |
| showValues | "true" | Whether or not to show value labels | Boolean |
| yTickFormat | "d => d" | The format function for y axis values | Function |
| bandwidth | "30" | The height of each row | Number |
| margin | "{ top: 0, right: 14, bottom: 0, left: 80 }" | The margin on each side of the chart in px | Object |
| duration | "300" | The total time of the animation in ms | Number |
Events
| Event | Argument | Description |
|---|---|---|
@select | { target, data } | Emitted when bar is clicked |
@hover | { target, data } | Emitted when bar is hovered |
Dependencies
- d3