A second axis
Since 0.1.0-alpha.22A second value axis
To plot a series in other units, such as a margin read against its revenue, add a second ChartValueAxis with a Name, here margin. Then give that series the name as its ValueAxis.
Static
Preview
- Revenue
- Gross margin
| Quarter | Revenue | Gross margin |
|---|---|---|
| Q1 2025 | $3,840,000 | 41% |
| Q2 2025 | $4,120,000 | 43% |
| Q3 2025 | $4,510,000 | 42% |
| Q4 2025 | $5,260,000 | 46% |
| Q1 2026 | $5,030,000 | 48% |
| Q2 2026 | $5,690,000 | 47% |
Code
@* Quarterly revenue in dollars, with the gross margin in percent on a second axis. *@
<Chart Items="_quarters" Argument="q => q.Quarter" Title="Revenue and gross margin">
<ChartValueAxis Format="C0" Title="Revenue" />
<ChartValueAxis Name="margin" Title="Gross margin" Format="P0" />
<ChartBarSeries Value="q => q.Revenue" Name="Revenue" />
<ChartLineSeries Value="q => q.Margin" Name="Gross margin" ValueAxis="margin" Color="var(--ib-chart-6)" />
</Chart>
{
private record QuarterResult(string Quarter, decimal Revenue, decimal Margin);
private readonly QuarterResult[] _quarters =
[
new("Q1 2025", 3_840_000, 0.41m), new("Q2 2025", 4_120_000, 0.43m), new("Q3 2025", 4_510_000, 0.42m),
new("Q4 2025", 5_260_000, 0.46m), new("Q1 2026", 5_030_000, 0.48m), new("Q2 2026", 5_690_000, 0.47m),
];
}Two charts side by side usually read better than one with two axes: readers compare the lines' heights, which mean nothing across scales. Use a second axis when one chart is the better fit.
The second axis has its own Format, Min, Max and Title. Its ticks fall on the first axis's grid lines, each a round step. Each title has a key in its series' color.
A second axis needs an upright chart, and a stacked chart's bars and areas stay on one axis. Reference lines, bands and notes are read on the second axis with the same ValueAxis; a statistic line follows its series.