Articles in this section
Category / Section

How to Use Margins for Chart Data Labels in Blazor Charts?

3 mins read

This article explains how to use margins for chart data labels in Blazor Charts.

Use Margins for Chart Data Labels

Blazor Charts provides an option to use margins for chart data labels. This can be achieved by utilizing ChartDataLabelMargin to set margins for data labels.

The code example below demonstrates how to use the left margin for chart data labels. Similarly, you can customize the top, right, and bottom margins.

Index.razor

@using Syncfusion.Blazor.Charts

<SfChart Height="100%" Width="100%">
   <ChartPrimaryXAxis EdgeLabelPlacement="EdgeLabelPlacement.Shift" ValueType="Syncfusion.Blazor.Charts.ValueType.Category" />
   <ChartSeriesCollection>
       <ChartSeries PointColorMapping="Color" LegendShape="Syncfusion.Blazor.Charts.LegendShape.Rectangle" DataSource="@MedalDetails" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Bar">
           <ChartMarker>
               <ChartDataLabel Fill="LightGray" Visible="true">
                   <ChartDataLabelFont Color="red" />
                   <ChartDataLabelMargin Left="20" />
               </ChartDataLabel>
           </ChartMarker>
       </ChartSeries>
   </ChartSeriesCollection>
</SfChart>

@code {    
   public class ChartData
   {
       public string X { get; set; }
       public double YValue { get; set; }
   }

   public List<ChartData> MedalDetails = new List<ChartData>
   {
       new ChartData { X= "USA", YValue= 46 },
       new ChartData { X= "GBR", YValue= 27 },
       new ChartData { X= "CHN", YValue= 26 },
       new ChartData { X= "UK", YValue= 23 },
       new ChartData { X= "AUS", YValue= 16 },
       new ChartData { X= "IND", YValue= 36 },
       new ChartData { X= "DEN", YValue= 12 },
       new ChartData { X= "MEX", YValue= 20 },
   };
} 

The following screenshot illustrates the output of the code snippet.

chrome_V8aq0QIX0f.png

Live Sample for Using Margins for Chart Data Labels

Conclusion

I hope you enjoyed learning how to use margins for chart data labels in Blazor Charts.

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