Dumbbell Chart
Signature
sp.build_dumbbell(
title: str,
labels: list[str],
values_start: list[float],
values_end: list[float],
*,
show_text: bool = True,
color_start: int = 0x6366f1,
color_end: int = 0xf43f5e,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
background: str | None = None,
gridlines: bool = True,
hover_json: str | None = None,
) -> Chart
Aliases: sp.dumbbell
Description
Dumbbell chart — a horizontal line connecting two data points per category, ideal for showing the gap or change between two states.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
labels | list[str] | required | Category labels |
values_start | list[float] | required | Left (start) values |
values_end | list[float] | required | Right (end) values |
show_text | bool | True | Show endpoint value labels |
color_start | int | 0x6366f1 | Start point color |
color_end | int | 0xf43f5e | End point color |
width | int | 900 | Canvas width |
height | int | 480 | Canvas height |
gridlines | bool | True | Vertical gridlines |
hover_json | str | None | None | Custom hover JSON |
Returns
Chart
Examples
Life expectancy 2000 vs 2023
import seraplot as sp
chart = sp.build_dumbbell(
"Life Expectancy: 2000 vs 2023",
labels=["Japan", "Germany", "Brazil", "India", "Nigeria"],
values_start=[81.2, 78.1, 70.4, 62.8, 46.5],
values_end=[84.3, 81.5, 75.2, 70.8, 54.9],
x_label="Age (years)",
)const sp = require('seraplot');
const chart = sp.build_dumbbell("Life Expectancy: 2000 vs 2023",
["Japan", "Germany", "Brazil", "India", "Nigeria"],
[81.2, 78.1, 70.4, 62.8, 46.5],
{
values_end: [84.3, 81.5, 75.2, 70.8, 54.9],
x_label: "Age (years)"
})import * as sp from 'seraplot';
const chart = sp.build_dumbbell("Life Expectancy: 2000 vs 2023",
["Japan", "Germany", "Brazil", "India", "Nigeria"],
[81.2, 78.1, 70.4, 62.8, 46.5],
{
values_end: [84.3, 81.5, 75.2, 70.8, 54.9],
x_label: "Age (years)"
})▶ Live Preview
See also
Signature
sp.build_dumbbell(
title: str,
labels: list[str],
values_start: list[float],
values_end: list[float],
*,
show_text: bool = True,
color_start: int = 0x6366f1,
color_end: int = 0xf43f5e,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
background: str | None = None,
gridlines: bool = True,
hover_json: str | None = None,
) -> Chart
Aliases: sp.dumbbell
Description
Graphique haltère — une ligne horizontale reliant deux valeurs par catégorie, idéal pour montrer l'écart ou l'évolution entre deux états.
Paramètres
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
labels | list[str] | requis | Étiquettes des catégories |
values_start | list[float] | requis | Valeurs de départ (gauche) |
values_end | list[float] | requis | Valeurs d'arrivée (droite) |
show_text | bool | True | Afficher les valeurs aux extrémités |
color_start | int | 0x6366f1 | Couleur du point de départ |
color_end | int | 0xf43f5e | Couleur du point d'arrivée |
width | int | 900 | Largeur du canvas |
height | int | 480 | Hauteur du canvas |
gridlines | bool | True | Lignes de grille verticales |
hover_json | str | None | None | JSON d'infobulle personnalisée |
Retourne
Chart
Exemples
import seraplot as sp
chart = sp.build_dumbbell(
"Espérance de vie : 2000 vs 2023",
labels=["Japon", "Allemagne", "Brésil", "Inde", "Nigéria"],
values_start=[81.2, 78.1, 70.4, 62.8, 46.5],
values_end=[84.3, 81.5, 75.2, 70.8, 54.9],
x_label="Âge (ans)",
)