Articles in this section
Category / Section

How to make a graph with multiple axes with Xamarin.Forms Charts

1 min read

This article explains how to add the multiple Y-axis in Xamarin.Forms Charts.

 

Consider, the use case to plot the graph for two products with different unit sales rate on the specific month as shown in the following image. It has been achieved by using the X-Axis and Y-Axis of the series.

 

multipl_Y_axis

 

Note:

By default, Cartesian series made using the SfChart's PrimaryAxis and SecondaryAxis.

 

How to add the multiple Y-axis in Xamarin.Forms Chart using XAML

 

Step 1: Declare the default PrimaryAxis and SecondaryAxis of SfChart with its customization.

 

…
<chart:SfChart.PrimaryAxis>
      <chart:DateTimeAxis Interval="1"  IntervalType="Months" /> 
</chart:SfChart.PrimaryAxis>
 
<chart:SfChart.SecondaryAxis>
      <chart:NumericalAxis Interval="5"  />
</chart:SfChart.SecondaryAxis>
…

 

Step 2: Declaration to add Y-axis for the required series.

 

…
<chart:SfChart.Series>
       <chart:SplineSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue2" Color="#d938d6" StrokeWidth="3" Label="Bullet">
            <chart:SplineSeries.YAxis>
                    <chart:NumericalAxis OpposedPosition="true" Minimum="15" Maximum="23" Interval="2" EdgeLabelsDrawingMode="Fit">
                     </chart:NumericalAxis>
              </chart:SplineSeries.YAxis>
         </chart:SplineSeries>
</chart:SfChart.Series>
…

 

How to add the multiple Y-axis in Xamarin.Forms Chart using C#

 

The following C# code example shows how to add Y-axis (or intend of X-axis) property in chart series.

 

…
SplineSeries splineSeries = new SplineSeries();
splineSeries.ItemsSource = viewModel.Data;
splineSeries.XBindingPath = "XValue";
splineSeries.YBindingPath = "YValue";
splineSeries.YAxis = new NumericalAxis()
{
       Minimum = 15,
       Maximum = 23,
       Interval = 2,
       IsVertical = true,
       OpposedPosition = true
};
…

 

View the sample in GitHub.

See also

Adding duplicate axis in SfChart

How to customize the axis label format based on the culture in Xamarin.Forms Chart (SfChart)

How to customize the axis labels

How to plot date-time values in vertical axes

How to change the data point selection color

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied