How to render multiple axes based on series color in Blazor Charts?
This article explains how to render multiple axes based on series colors.
Rendering Multiple Axes Based on Series Colors:
Blazor Charts provides an option to customize the color of a required axis using its corresponding series color.
This can be achieved by specifying a color for each series using the Fill property in the ChartSeries tag. Then multiple axes can be rendered using the ChartAxes tag, and each ChartAxis can be placed in the required position using the OpposedPosition property. The color of the axis line, title, and labels can be changed by specifying Color property for ChartAxisLineStyle, ChartAxisTitleStyle and ChartAxisLabelStyle.
The code example below demonstrates how to render multiple axes based on series colors.
Index.razor:
@using Syncfusion.Blazor.Charts
<SfChart Title="XYZ - Stock Analysis (2009 - 2016)">
<ChartAxes>
<ChartAxis Title="Operating Cashflow (thousand crores)" Minimum="0" Maximum="10" Interval="2" Name="YAxis" OpposedPosition="true">
<ChartAxisTitleStyle Color="#00E396" />
<ChartAxisLineStyle Color="#00E396"></ChartAxisLineStyle>
<ChartAxisLabelStyle Color="#00E396"></ChartAxisLabelStyle>
</ChartAxis>
<ChartAxis Title="Revenue (thousand crores)" Minimum="0" Maximum="60" Interval="10" Name="YAxis2" OpposedPosition="true">
<ChartAxisTitleStyle Color="#FEB019" />
<ChartAxisLineStyle Color="#FEB019"></ChartAxisLineStyle>
<ChartAxisLabelStyle Color="#FEB019"></ChartAxisLabelStyle>
</ChartAxis>
</ChartAxes>
<ChartSeriesCollection>
<ChartSeries Fill="rgba(0,143,251,0.85)" Name="Income" LegendShape="LegendShape.Circle" DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Column" />
<ChartSeries Fill="rgba(0,227,150,0.85)" Name="Cashflow" LegendShape="LegendShape.Circle" DataSource="@WeatherReports" XName="X" YName="Y1" YAxisName="YAxis" Type="ChartSeriesType.Column" />
<ChartSeries Fill="rgba(254,176,25,0.85)" Name="Revenue" LegendShape="LegendShape.Circle" DataSource="@WeatherReports" XName="X" YName="Y2" YAxisName="YAxis2" Type="ChartSeriesType.Line" />
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public DateTime X { get; set; }
public double Y { get; set; }
public double Y1 { get; set; }
public double Y2 { get; set; }
}
public List<ChartData> WeatherReports = new List<ChartData>
{
new ChartData { X = new DateTime(2009,01,01), Y = 1.4, Y1 = 1.1, Y2 = 20 },
new ChartData { X = new DateTime(2010,01,01), Y = 2, Y1 = 3, Y2 = 29 },
//...
};
}
The following screenshot illustrates the output of the code snippet.
Output:
Live Sample for Multiple Axes Based on Series Colors
Conclusion:
We hope you enjoyed learning how to render multiple axes based on series colors in the Blazor Chart component.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!