How to display additional data in the tooltip of WPF Chart ?
Description
The WPF SfChart supports customizing tooltips to display additional information from the underlying data model of the populated items source within the chart tooltip using the TooltipTemplate property of the chart series.
By default, the tooltip shows only the corresponding Y-axis value of that segment. However, you can define a custom TooltipTemplate to include more details from the data model. For example, you can display both the country's name and its population in the tooltip, as shown in the below code example.
XAML
<Window.DataContext> <local:ViewModel/> </Window.DataContext> <Window.Resources> <DataTemplate x:Key="tooltipTemplate"> <StackPanel Orientation="Horizontal"> <!--Template element has DataContext as its Segment named Item. From it, you can access the correponding Model--> <TextBlock FontFamily="Segoe UI" Foreground="White"> <Run Text="{Binding Item.Country}"/> <Run Text=":"/> <Run Text="{Binding Item.Population}"/> </TextBlock> </StackPanel> </DataTemplate> </Window.Resources> <StackPanel> <syncfusion:SfChart Header="Population growth" Width="353" Height="298"> <syncfusion:SfChart.PrimaryAxis> <syncfusion:CategoryAxis/> </syncfusion:SfChart.PrimaryAxis> <syncfusion:SfChart.SecondaryAxis> <syncfusion:NumericalAxis/> </syncfusion:SfChart.SecondaryAxis> <syncfusion:ColumnSeries ItemsSource="{Binding Data}" XBindingPath="Country" YBindingPath="Population" ShowTooltip="True" TooltipTemplate="{StaticResource tooltipTemplate}"/> </syncfusion:SfChart> </StackPanel>
Output
You can download the complete sample in this GitHub location.
See also
How to display the tooltip when the mouse is in any region of the FastLineBitmapSeries in WPF Charts
How to customize WPF Charts tooltip
How to set the duration for chart tooltip
Conclusion
I hope you enjoyed learning about how to display more data in the tooltip of WPF Chart.
You can refer to our WPF Chart featuretour 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 WPFChart demo 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!