Skip to content
On this page

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 ​

NameDefaultDescriptionType
data"[]"The datasetArray
colorLine"#9CA3AF"The color for the line between dotsString
colorDot1"#F59E0B"The color for the dot of category 1String
colorDot2"#3B82F6"The color for the dot of category 2String
colorBg"#f3f4f6"The background color for highlighted rowString
colorAxis"#6B7280"The color of the x axisString
xAxisDomain"[0, 100]"The min and max value for x axisArray
showValues"true"Whether or not to show value labelsBoolean
yTickFormat"d => d"The format function for y axis valuesFunction
bandwidth"30"The height of each rowNumber
margin"{ top: 0, right: 14, bottom: 0, left: 80 }"The margin on each side of the chart in pxObject
duration"300"The total time of the animation in msNumber

Events ​

EventArgumentDescription
@select{ target, data }Emitted when bar is clicked
@hover{ target, data }Emitted when bar is hovered

Dependencies ​

  • d3