Skip to content
On this page

Charts > Beeswarm Chart ​

A beeswarm chart is a visualization that displays individual data points along a single axis, avoiding overlap by spreading them out horizontally based on their distribution.

The Chart ​

Profanity Distribution in Tarantino's "Pulp Fiction": Frequency of 'F***' Variants. Source: FiveThirtyEight

Download example CSV
Copy HTML

Playground ​

Data

Value of compare mark
Divisions for region hover
Hover by region
Zoom in on selected dots

Animation

Total time of animation

Style

Use forces to layout dots
Random Dot Radius
Flexible Dot Radius
Show X Axis
Use color scale
Dot radius
Minimum dot radius
Space between dots
Color of dots
Color of hover background

Usage Example ​

vue
<template>
  <div class="relative">
    <BeeswarmChart :data="data" @hover="hover = $event" @brush="select" />
    <button
      v-show="selected"
      @click="reset"
      :animate-enter="animateEnter"
      class="ot-btn absolute top-0 right-0 px-2 text-xs"
    >
      Return
    </button>
  </div>
</template>

<script setup>
const selected = ref(null);
const animateEnter = ref(true);

const select = (e) => {
  if (e && zoomOnBrush.value) selected.value = e.data;
};
const reset = () => {
  animateEnter.value = false;
  selected.value = null;
};
</script>

Component API ​

The beeswarm is built using SVG and d3. The dots are animated using GSAP on enter, and d3 transition on update.

The components supports hovering individual dots, hovering by region, and brushing (dragging the mouse to select a region).

Data ​

js
[
  {
    id: "ESP",
    name: "Spain",
    value: 75,
  },
  ...
]

INFO

Optional: color

Props ​

NameDefaultTypeDescription
data[]ArrayThe dataset
radius6NumberThe size of dots
padding0.2NumberThe space between circles
axisLabel-StringThe label for the main axis
horizontaltrueBooleanThe direction of the main axis
color#0B4F96StringThe color of the dots
useColorScalefalseBooleanWhether or not to use a color scale for dots
domainnullArrayThe min and max value of the main axis
showAxistrueBooleanWhether or not to show the axis
showRefLinetrueBooleanWhether or not to show the middle reference line
refLineColor#d1d5dbStringThe color of the reference line
distanceFromAxis50NumberThe amount of space between axis and chart
marginCustomnullObjectThe margin around chart: top, right, bottom, left
useForcesfalseBooleanWhether or not to use a force layout to position dots
compareValuenullNumberThe value for the compare mark
showFlagsfalseBooleanWhether or not to show country flags on hover
duration2NumberThe duration of the animation in seconds
selectednullString/NumberThe id of the selected dot
selectedColor#F87171StringThe color for the selected dot
hoverByRegiontrueBooleanWhether or not to hover dots by region
numberOfBgRects20NumberThe number of regions to divide the dots in
hoverRectColor#d1d5dbStringThe background color for the hovered region
flexibleRadiusfalseBooleanWhether or not to scale radius based on value
minRadius3NumberThe minimum dot size
scaleTypescaleLinearStringThe type of scale to use for the main axis
allowBrushfalseBooleanWhether or not to allow brushing events
clearBrushOnMouseUpfalseBooleanWhether or not to remove the brush when selection is done (useful when it's followed by zooming)
animateEntertrueBooleanWhether or not to animate new dots
adaptSizefalseBooleanWhether or not to adapt cross axis size to num of dots

Events ​

EventArgumentDescription
@hover{ target, data }, null Emitted when dot or region is hovered
@select{ target, data }Emitted when dot is clicked
@brush{ target, data }Emitted when a region is selected using brushing

Dependencies ​

  • d3
  • GSAP
  • accurate-beeswarm-plot