Articles in this section
Category / Section

How to Configure the Syncfusion Theme for .NET MAUI Chart(SfCartesianChart)?

3 mins read

This guide will walk you through configuring and customizing the .NET MAUI Syncfusion® theme for the SfCartesianChart. Syncfusion® themes enable you to apply colors uniformly to .NET MAUI Cartesian Charts, providing a consistent look and feel for your applications.

Let’s take a look at the following sections:

  1. How to Set the Theme for the Application
  2. Dynamically Changing Themes
  3. Overriding the Default Theme
How to Set the Theme for the Application

By default, Syncfusion® provides support for both light and dark themes through the inclusion of a SyncfusionThemeResourceDictionary.

Initialize and assign the desired theme in your application, modify the App.xaml file as follows:

<Application xmlns:syncTheme="clr-namespace:Syncfusion.Maui.Themes;assembly=Syncfusion.Maui.Core">
   
   <Application.Resources>
       <ResourceDictionary>
           <ResourceDictionary.MergedDictionaries>
               <syncTheme:SyncfusionThemeResourceDictionary VisualTheme="MaterialLight"/>
           </ResourceDictionary.MergedDictionaries>
       </ResourceDictionary>
   </Application.Resources>

</Application> 

Light Theme

Demo for Cartesian Chart Light Theme

Dark Theme

Demo for Cartesian Chart Dark Theme

Dynamically Changing Themes

Syncfusion® allows for dynamic theme switching within your application. This can be achieved by updating the VisualTheme property at runtime. Here is an example in C#:

ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
if (mergedDictionaries != null)
{
    var theme = mergedDictionaries.OfType<SyncfusionThemeResourceDictionary>().FirstOrDefault();
    if (theme != null)
    {
        if (state == false)
        {
            theme.VisualTheme = SfVisuals.MaterialLight;
        }
        else
        {
            theme.VisualTheme = SfVisuals.MaterialDark
        }
    }
} 

DemoTheme.gif

Overriding the Default Theme

The theme resource dictionary contains a set of keys that are mapped to styles in control style dictionaries. The default appearance of themes can be customized by overriding these key values. You can find the keys for the Cartesian Chart here: Cartesian Chart Theme Keys.

For example, the major grid lines and tooltip background values are customized by overriding theme keys.

<Application xmlns:syncTheme="clr-namespace:Syncfusion.Maui.Themes;assembly=Syncfusion.Maui.Core">
   
   <Application.Resources>
       <ResourceDictionary>
           <ResourceDictionary.MergedDictionaries>
               <syncTheme:SyncfusionThemeResourceDictionary VisualTheme="MaterialLight"/>

               <ResourceDictionary>
                   <Color x:Key="SfCartesianChartMajorGridLineStroke">Lime</Color>
                   <Color x:Key="SfCartesianChartTooltipBackground">Pink</Color>
               </ResourceDictionary>

           </ResourceDictionary.MergedDictionaries>
       </ResourceDictionary>
   </Application.Resources>
</Application> 

Demo for Theme Key Customization

For more information, please refer to the Syncfusion® .NET MAUI Cartesian Chart Theme Demo

Conclusion

I hope you enjoyed learning how to configure and customize themes in your .NET MAUI applications using the Syncfusion®'s SfCartesianChart control.
You can refer to our .NET MAUI Cartesian Chart feature tour page to learn 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 components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls. Please let us know in the 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