How to customize the title of a .NET MAUI Chart using any view and title wrapping?
In a .NET MAUI Cartesian Charts, the chart title provides essential context for the data being presented. This guide explains how to customize the chart titles, including using any view for the title and enabling title wrapping.
Image at chart title:
To create a custom view title, any view can be added to the chart title.
[XAML]
<chart:SfCartesianChart.Title>
<Grid ColumnDefinitions="Auto,Auto">
<Image Grid.Column="0" Source="sales.png"/>
<Label Grid.Column="1" Text="Sales Report"/>
</Grid>
</chart:SfCartesianChart.Title>
[C#]
SfCartesianChart chart = new SfCartesianChart();
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
Image image = new Image();
image.Source = "sales.png";
image.HeightRequest = 20;
image.WidthRequest = 20;
Grid.SetColumn(image, 0);
Label label = new Label();
label.Text = "Sales Report";
Grid.SetColumn(label, 1);
grid.Children.Add(image);
grid.Children.Add(label);
chart.Title = grid;
Wrap The Chart Title:
To include a multi-line title, it can be easily wrapped using the built-in API. This can be achieved by setting the LineBreakMode property to WordWrap in the ChartTitle.
[XAML]
<chart:SfCartesianChart>
<chart:SfCartesianChart.Title>
<Label Text="Comparison of Monthly Sales by Product Category for the Fiscal Year 2021-2022" LineBreakMode="WordWrap"/>
</chart:SfCartesianChart.Title>
</chart:SfCartesianChart>
[C#]
SfCartesianChart chart= new SfCartesianChart();
chart.Title = new Label
{
Text = "Comparison of Monthly Sales by Product Category for the Fiscal Year 2021-2022",
LineBreakMode = LineBreakMode.WordWrap.
};
Conclusion
I hope you enjoyed learning customizing the title of a .NET MAUI Chart: Using Any View and Title Wrapping.
You can refer to our .NET MAUI Charts feature tour page to know about its other groundbreaking feature representations. Explore our .NET MAUI Charts documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the Licence and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Charts and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!