Butterfly chart
Two series back to back on a shared category axis, the categories named between them. The population pyramid is the classic case.
A butterfly chart compares two series category by category. label-field names each row, and the two
c2-chart-series grow away from each other from a gutter in the middle, where the categories are written: the
first towards the start, the second towards the end. A population pyramid (age bands, men against women) is the
classic case; before and after, or two products’ scores on the same questions, read just as well.
Both sides share one scale, rounded to even steps, so equal values draw equal lengths. The start side’s axis is
mirrored rather than negated: every value, tick and tooltip reads as the number it is. The tooltip lists both
sides of a row, and the legend highlights a side (or, with legend-action="toggle", switches it off).
Import
import '@c2n/components/chart/butterfly-chart'This chart draws with ECharts, a peer dependency it loads on first draw: npm install echarts.
Usage
Data and order
Rows are drawn top to bottom in data order: a population pyramid lists its oldest band first. Exactly two series are drawn; with one, the chart says it needs two, and any after the second are left out with a console warning.
Styling
--c2-chart__gutter--width (56px by default) is the space between the sides, where the categories are written:
widen it for longer names. --c2-chart__bar--thickness (0.72) is the share of each row a bar fills, and the
shared --c2-chart__bar--border-radius (0 to 0.5) rounds each bar’s value end, away from the gutter. The two
sides take --c2-chart__series-1--color and --c2-chart__series-2--color.