How to create a graph with multiple axes using Blazor Chart?
This article explains how to add multiple Y axes in Blazor Charts.
Blazor Chart with Multiple Y Axes:
Blazor Charts provide support for using multiple axes at simultaneously by using the ChartAxes.
The ChartAxes is a secondary axis collection that can be used to add ānā number of axes to the chart in addition to the primary X and Y axis. By mapping a series to an axis using its unique name, the series can be linked to that axis.
In the example below, the series and axis are linked together by using the Name property of ChartAxis and by providing the same name to the YAxisName property.
<ChartAxes>
<ChartAxis Name="YAxis" OpposedPosition="true"/>
</ChartAxes>
<ChartSeriesCollection>
...
<ChartSeries YAxisName="YAxis" DataSource="@WeatherReports" XName="Month" YName="Product2" Fill="pink" >
</ChartSeries>
</ChartSeriesCollection>
The following code snippet illustrates how to create a graph with multiple Y axes.
Index.razor:
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" Interval="1" IntervalType="IntervalType.Months">
<ChartAxisMajorGridLines Width="0"/>
<ChartAxisMinorGridLines Width="0"/>
</ChartPrimaryXAxis>
<ChartPrimaryYAxis>
<ChartAxisMajorGridLines Width="0"/>
<ChartAxisMinorGridLines Width="0"/>
</ChartPrimaryYAxis>
<ChartAxes>
<ChartAxis Name="YAxis" OpposedPosition="true" Interval="10" Minimum="10" Maximum="50"/>
</ChartAxes>
<ChartSeriesCollection>
<ChartSeries DataSource="@WeatherReports" XName="Month" YName="Product1" Type="ChartSeriesType.Spline" Fill="blue">
</ChartSeries>
<ChartSeries DataSource="@WeatherReports" XName="Month" YName="Product2" Type="ChartSeriesType.Spline" Fill="pink" YAxisName="YAxis">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class Chart
{
public DateTime Month { get; set; }
public double Product1 { get; set; }
public double Product2 { get; set; }
}
public List<Chart> WeatherReports = new List<Chart>
{
new Chart { Month = new DateTime(2005, 01, 01), Product1 = 21, Product2 = 26 },
new Chart { Month = new DateTime(2005, 02, 01), Product1 = 24, Product2 = 20 },
new Chart { Month = new DateTime(2005, 03, 01), Product1 = 36, Product2 = 30 },
new Chart { Month = new DateTime(2005, 04, 01), Product1 = 30, Product2 = 40 },
new Chart { Month = new DateTime(2005, 05, 01), Product1 = 25, Product2 = 35 },
new Chart { Month = new DateTime(2005, 06, 01), Product1 = 20, Product2 = 30 },
new Chart { Month = new DateTime(2005, 07, 01), Product1 = 40, Product2 = 20 },
new Chart { Month = new DateTime(2005, 08, 01), Product1 = 35, Product2 = 45 },
};
}
The following screenshot shows the output of the above code snippet.
Output:
Conclusion
We hope you enjoyed learning how to add multiple Y axes 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!