How to wrap the axis labels in WPF SfChart?
In WPF Chart (SfChart), you can wrap axis labels by customizing the LabelTemplate property of the axis. This enables you to control the appearance and layout of axis labels, such as applying text wrapping for long labels that don't fit within the available space.
In this example, we define a custom DataTemplate for the axis labels, where we use text wrapping within a TextBlock inside a Grid. This ensures that long labels are displayed properly without overflowing the available space.
XAML
<Grid> <Grid.Resources> <DataTemplate x:Key="labelTemplate"> <Grid Height="70" Width="40"> <TextBlock TextWrapping="Wrap" Text="{Binding LabelContent}" FontSize="12"/> </Grid> </DataTemplate> </Grid.Resources>
<chart:SfChart> <chart:SfChart.PrimaryAxis> <chart:CategoryAxis LabelTemplate="{StaticResource labelTemplate}"/> </chart:SfChart.PrimaryAxis>
...
</chart:SfChart> </Grid>
Output
The following demo image illustrates the axis labels wrapping, following the implemented steps.
Conclusion
I hope you enjoyed learning how to wrap the axis labels in WPF SfChart.
You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples 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, Direct-Trac, or feedback portal. We are always happy to assist you!