Articles in this section
Category / Section

How to customize the axis grid line for .NET MAUI Chart?

2 mins read

This article explains how to customize the axis grid line in the .NET MAUI Chart.
The .NET MAUI Chart provides support to customize the axis grid lines with the help of the MajorGridLineStyle, MinorGridLineStyle, MajorTickStyle and MinorTickStyle properties of the chart axis. These properties provide options to change the width, style (such as dashes), and color of grid lines.
The visibility of the major gridlines can be controlled using the ShowMajorGridLines property. The default value of ShowMajorGridLines is true.
Step 1: Customize the appearance of major gridlines using the MajorGridLineStyle property in the ChartAxis.
[XAML]

<chart:SfCartesianChart>
    . . .
        <chart:SfCartesianChart.YAxes>
            <chart:NumericalAxis ShowMajorGridLines="True">
                <chart:NumericalAxis.MajorGridLineStyle>
                    <chart:ChartLineStyle Stroke="Blue"									          StrokeWidth="2"/>     
                </chart:NumericalAxis.MajorGridLineStyle>
                       </chart:NumericalAxis>
       </chart:SfCartesianChart.YAxes>
<chart:SfCartesianChart>

[C#]

SfCartesianChart chart = new SfCartesianChart();
    . . .
NumericalAxis secondaryAxis = new NumericalAxis();
secondaryAxis.ShowMajorGridLines = true;
ChartLineStyle axisLineStyle = new ChartLineStyle();
axisLineStyle.Stroke = Colors.Blue;
axisLineStyle.StrokeWidth = 2;
secondaryAxis.MajorGridLineStyle = axisLineStyle;
chart.YAxes.Add(secondaryAxis);

Step 2: Set the minor gridlines style to a dashed pattern using the StrokeDashArray property.
[XAML]

<chart:SfCartesianChart>
    <chart:SfCartesianChart.Resources>
            <DoubleCollection x:Key="dashArray">
                <x:Double>3</x:Double>
                <x:Double>3</x:Double>
            </DoubleCollection>
    </chart:SfCartesianChart.Resources>
    . . .
        <chart:SfCartesianChart.YAxes>
            <chart:NumericalAxis ShowMinorGridLines="True"  
                                 MinorTicksPerInterval="2">
                <chart:NumericalAxis.MinorGridLineStyle>
                    <chart:ChartLineStyle Stroke="Green"
                                          StrokeWidth="1"
                                          StrokeDashArray="{StaticResource dashArray}"/>
                </chart:NumericalAxis.MinorGridLineStyle>
                       </chart:NumericalAxis>
       </chart:SfCartesianChart.YAxes>
<chart:SfCartesianChart>

[C#]

SfCartesianChart chart = new SfCartesianChart();
    . . .
DoubleCollection doubleCollection = new DoubleCollection();
doubleCollection.Add(3);
doubleCollection.Add(3);
NumericalAxis secondaryAxis = new NumericalAxis();
secondaryAxis.ShowMinorGridLines = true;
secondaryAxis.MinorTicksPerInterval = 2;
ChartLineStyle axisLineStyle = new ChartLineStyle();
axisLineStyle.Stroke = Colors.Green;
axisLineStyle.StrokeWidth = 1;
axisLineStyle.StrokeDashArray = doubleCollection;
secondaryAxis.MinorGridLineStyle = axisLineStyle;
chart.YAxes.Add(secondaryAxis);

Output
Screenshot 2023-06-20 145004
Explore the runnable demo from this GitHub location
Conclusion
I hope you enjoyed learning about how to customize the axis grid line for .NET MAUI Chart (SfCartesianChart).
You can refer to our .NET MAUI Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI Chart documentation to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

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