Appearance
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
| Name | Default | Type | Description |
|---|---|---|---|
data | [] | Array | The dataset |
radius | 6 | Number | The size of dots |
padding | 0.2 | Number | The space between circles |
axisLabel | - | String | The label for the main axis |
horizontal | true | Boolean | The direction of the main axis |
color | #0B4F96 | String | The color of the dots |
useColorScale | false | Boolean | Whether or not to use a color scale for dots |
domain | null | Array | The min and max value of the main axis |
showAxis | true | Boolean | Whether or not to show the axis |
showRefLine | true | Boolean | Whether or not to show the middle reference line |
refLineColor | #d1d5db | String | The color of the reference line |
distanceFromAxis | 50 | Number | The amount of space between axis and chart |
marginCustom | null | Object | The margin around chart: top, right, bottom, left |
useForces | false | Boolean | Whether or not to use a force layout to position dots |
compareValue | null | Number | The value for the compare mark |
showFlags | false | Boolean | Whether or not to show country flags on hover |
duration | 2 | Number | The duration of the animation in seconds |
selected | null | String/Number | The id of the selected dot |
selectedColor | #F87171 | String | The color for the selected dot |
hoverByRegion | true | Boolean | Whether or not to hover dots by region |
numberOfBgRects | 20 | Number | The number of regions to divide the dots in |
hoverRectColor | #d1d5db | String | The background color for the hovered region |
flexibleRadius | false | Boolean | Whether or not to scale radius based on value |
minRadius | 3 | Number | The minimum dot size |
scaleType | scaleLinear | String | The type of scale to use for the main axis |
allowBrush | false | Boolean | Whether or not to allow brushing events |
clearBrushOnMouseUp | false | Boolean | Whether or not to remove the brush when selection is done (useful when it's followed by zooming) |
animateEnter | true | Boolean | Whether or not to animate new dots |
adaptSize | false | Boolean | Whether or not to adapt cross axis size to num of dots |
Events
| Event | Argument | Description |
|---|---|---|
@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