Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

A second axis

Since 0.1.0-alpha.22
A second value axis across the plot from the first, for a measure in other units read against the same arguments, with ticks on the first axis's grid lines.

A 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 and gross margin
  • Revenue
  • Gross margin
Arrow keys move between values; Escape hides the tooltip.

Code

SecondAxis.razor
@* 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>

@code {
    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.

Connection lost

Rejoining the server…