Bubble chart
An ECharts scatter plot with a third measure encoded as bubble area, for comparing how two measures relate while showing how much each point weighs.
The default example plots approximate, rounded 2023 figures after the World Bank’s World Development Indicators (GDP per capita in current US$, life expectancy at birth, population in millions); check the source before reusing them. The product-portfolio example (a growth–share matrix: each business unit is a column holding its products’ market growth) is illustrative.
Import
import '@c2n/components/chart/bubble-chart'This chart draws with ECharts, a peer dependency it loads on first draw: npm install echarts.
Usage
x-field and y-field place a bubble, size-field sizes it and label-field names it in the tooltip and inside the bubble. The rows can take either shape:
- One row per point.
series-fieldnames the field that says which series a row belongs to, andy-fieldholds the value. The series are that field’s distinct values, in the order they first appear. Ac2-chart-serieswhosefieldis one of those values relabels or recolours it, and declaring any of them limits the chart to the ones declared. - One column per series. Each
c2-chart-seriesreads its ownfieldas the y value, as on the scatter chart, and every series shares the one size column. A row may carry only one series’ field.
Size is encoded as area: the diameter grows with the square root of the value, between --c2-chart__bubble--min-size and --c2-chart__bubble--max-size, so a value twice as large looks twice as large. The largest size in the data draws at the maximum; set size-max to pin that value when several charts must be compared. Within each series the larger bubbles are drawn first, so the small ones stay on top and hoverable.
Each axis is widened past the data until every bubble fits inside the plot, and its ends are rounded to ticks: a smallest x of 16 with a large bubble on it starts the axis at 14, not at 16 with half the bubble over the axis. A log axis widens to whole decades.
x-scale="log" and y-scale="log" suit a measure that spans orders of magnitude; rows at or below zero are skipped on a log axis. bubble-labels is auto (label the bubbles whose text fits inside), all or none. size-legend ends the built-in legend with a key to the sizes, titled by size-label, as in the first example; it is off by default. The key is part of the built-in legend, so legend="none" or a linked c2-chart-legend hides it too.
point-hover, point-click and tooltip-change report the row, not its draw position, and carry its size (and label); formatSize formats the size in the tooltip and the key.
Styling
Every visual detail of the bubbles is a CSS custom property: fill opacity (--c2-chart__bubble--opacity, and __hover--opacity for the hovered bubble), outline width, the minimum and maximum diameters, the bubble label’s colour and size, and the size key’s colour. Series colours come from --c2-chart__series-1…8--color as on every chart.