Articles in this section
Category / Section

How to set font family for elements in Blazor Charts?

3 mins read

This article explains how to set font family for elements in Blazor Charts.

Applying a font family to chart elements

Blazor Charts provides an option to apply the font properties like FontFamily, FontWeight, FontStyle, Color and Size for all chart elements using property binding.

This can be achieved by specifying the required FontFamily using a property and assigning its name to each element in the chart using ChartTitleStyle for title, ChartSubTitleStyle for subtitle, ChartAxisLabelStyle for axis labels, ChartAxisTitleStyle for axis titles, ChartDataLabelFont for data labels, ChartTooltipTextStyle for tooltip and ChartLegendTextStyle for legend. Likewise, the other font properties can also be applied.

The below code example demonstrates how to apply font family for chart.

Index.razor

@using Syncfusion.Blazor.Charts
<SfChart Title="Olympic Medals" SubTitle="RIO">
   <ChartTitleStyle FontFamily="@fontFamily"></ChartTitleStyle>
   <ChartSubTitleStyle FontFamily="@fontFamily"></ChartSubTitleStyle>
   <ChartPrimaryXAxis Title="Countries" ValueType="Syncfusion.Blazor.Charts.ValueType.Category">
       <ChartAxisLabelStyle FontFamily="@fontFamily"></ChartAxisLabelStyle>
       <ChartAxisTitleStyle FontFamily="@fontFamily"></ChartAxisTitleStyle>
   </ChartPrimaryXAxis>
   <ChartPrimaryYAxis Title="Count">
       <ChartAxisLabelStyle FontFamily="@fontFamily"></ChartAxisLabelStyle>
       <ChartAxisTitleStyle FontFamily="@fontFamily"></ChartAxisTitleStyle>
   </ChartPrimaryYAxis>
   <ChartSeriesCollection>
       <ChartSeries DataSource="@MedalDetails" Name="Gold" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
           <ChartMarker>
               <ChartDataLabel Visible=true>
                   <ChartDataLabelFont FontFamily="@fontFamily"></ChartDataLabelFont>
               </ChartDataLabel>
           </ChartMarker>
       </ChartSeries>
   </ChartSeriesCollection>
   <ChartTooltipSettings Enable="true">
       <ChartTooltipTextStyle FontFamily="@fontFamily"></ChartTooltipTextStyle>
   </ChartTooltipSettings>
   <ChartLegendSettings Visible=true>
      <ChartLegendTextStyle FontFamily="@fontFamily"></ChartLegendTextStyle>
   </ChartLegendSettings>
</SfChart>

@code {
   public string fontFamily { get; set; } = "Arial";
   public class ChartData
   {
       public string X { get; set; }
       public double Y { get; set; }
   }

   public List<ChartData> MedalDetails = new List<ChartData>
   {
       new ChartData { X= "South Korea", Y= 39.4 },
       new ChartData { X= "India", Y= 61.3 },
       new ChartData { X= "Pakistan", Y= 20.4 },
       new ChartData { X= "Germany", Y= 65.1 },
       new ChartData { X= "Australia", Y= 15.8 },
       new ChartData { X= "Italy", Y= 29.2 },
       new ChartData { X= "United Kingdom", Y= 44.6 },
       new ChartData { X= "Saudi Arabia", Y= 9.7 },
       new ChartData { X= "Russia", Y= 40.8 },
       new ChartData { X= "Mexico", Y= 31 },
       new ChartData { X= "Brazil", Y= 75.9 },
       new ChartData { X= "China", Y= 51.4 }
   };
}

The following screenshot illustrates the output of the code snippet.

Output

image.png

Live Sample for Font Family Customization

Conclusion

I hope you enjoyed learning how to set font family for all chart elements in Blazor Chart Component.

You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart 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