Articles in this section
Category / Section

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

3 mins read

This article explains how to customize the axis grid line in the .NET MAUI Chart.
The .NET MAUI Chart allows customization using properties such as MajorGridLineStyle, MinorGridLineStyle, MajorTickStyle and MinorTickStyle for changing 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

Download the complete sample from GitHub.

Conclusion
I hope you enjoyed learning how to customize the axis grid line for .NET MAUI Chart (SfCartesianChart).
You can refer to our .NET MAUI Chart feature tour page to know about its other groundbreaking feature representations. Explore our .NET MAUI Chart documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.
Please let us know in comments section if you have any queries or require clarification. 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