Articles in this section
Category / Section

How to Apply a Theme in Blazor Charts?

3 mins read

This article explains how to apply a theme in Blazor Charts using the Theme property of the SfChart component.

Overview

Blazor Charts allows you to customize the appearance of charts using predefined themes. You can apply a theme by setting the Theme property in the SfChart component. This enables consistent styling aligned with your application’s look and feel.

Code Example

The following example demonstrates how to apply the MaterialDark theme to a chart.

@using Syncfusion.Blazor.Charts
@using Syncfusion.Blazor

<div>
   <SfChart Title="Olympic Medal Counts - RIO" Theme="@Theme">
       <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" Interval="1">
       </ChartPrimaryXAxis>
       <ChartPrimaryYAxis Title="Medal Count" Maximum="50" Interval="10">
       </ChartPrimaryYAxis>
       <ChartSeriesCollection>
           <ChartSeries TooltipMappingName="MappingName" DataSource="@ChartPoints" XName="Country" YName="GoldMedal" Name="Gold" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
           </ChartSeries>
           <ChartSeries TooltipMappingName="MappingName" DataSource="@ChartPoints" XName="Country" YName="SilverMedal" Name="Silver" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
           </ChartSeries>
           <ChartSeries TooltipMappingName="MappingName" DataSource="@ChartPoints" XName="Country" YName="BronzeMedal" Name="Bronze" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
           </ChartSeries>
       </ChartSeriesCollection>
   </SfChart>
</div>
@code {
   private Theme Theme { get; set; }
   public List<ColumnChartData> ChartPoints { get; set; } = new List<ColumnChartData>
   {
       new ColumnChartData { Country = "GBR", GoldMedal = 27, SilverMedal = 23, BronzeMedal = 17, MappingName = "Great Britain" },
       new ColumnChartData { Country = "CHN", GoldMedal = 26, SilverMedal = 18, BronzeMedal = 26, MappingName = "China" },
       new ColumnChartData { Country = "AUS", GoldMedal = 8, SilverMedal = 11, BronzeMedal = 10, MappingName = "Australia" },
       new ColumnChartData { Country = "RUS", GoldMedal = 19, SilverMedal = 17, BronzeMedal = 20, MappingName = "Russia" },
       new ColumnChartData { Country = "GER", GoldMedal = 17, SilverMedal = 10, BronzeMedal = 15, MappingName = "Germany" },
       new ColumnChartData { Country = "UA", GoldMedal = 2, SilverMedal = 5, BronzeMedal = 24, MappingName = "Ukraine" },
       new ColumnChartData { Country = "ES", GoldMedal = 7, SilverMedal = 4, BronzeMedal = 6, MappingName = "Spain" },
       new ColumnChartData { Country = "UZB", GoldMedal = 4, SilverMedal = 2, BronzeMedal = 7, MappingName = "Uzbekistan" },
       new ColumnChartData { Country = "JPN", GoldMedal = 12, SilverMedal = 8, BronzeMedal = 21, MappingName = "Japan" },
       new ColumnChartData { Country = "NL", GoldMedal = 8, SilverMedal = 7, BronzeMedal = 4, MappingName = "NetherLand" },
       new ColumnChartData { Country = "USA", GoldMedal = 46, SilverMedal = 37, BronzeMedal = 38, MappingName = "United States" },
   };
   protected override void OnInitialized()
   {
       Theme = Theme.MaterialDark;
   }
   public class ColumnChartData
   {
       public string Country { get; set; }
       public double GoldMedal { get; set; }
       public double SilverMedal { get; set; }
       public double BronzeMedal { get; set; }
       public string MappingName { get; set; }
   }
} 

Output

The chart will render with the Material Dark theme applied.

msedge_6PTG4CG3GT.png

Live Sample

You can view a live example of applying a theme to Blazor Charts here.

Conclusion:

We hope you found this guide helpful in learning how to apply a theme in Blazor Charts. For more features, visit our [Blazor Charts feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our [Blazor Charts example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries 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!

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