How to customize the default tooltip background in WPF Chart?
The WPF Chart allows you to display the y-value or data point value of the related ChartSegment, when the user moves pointer hovers over any chart segment. To enable Chart tooltip, set the ShowTooltip property of ChartSeries to true.
The following steps explain how to customize the default tooltip arrow pointer background:
Step 1: Create an instance of ChartTooltipBehavior class and add it to the SfChart Behaviors collection.
<chart:SfChart.Behaviors> <chart:ChartTooltipBehavior Position="Pointer"/> </chart:SfChart.Behaviors>
Step 2: Create a style targeting Path and set the Stroke and Fill properties to transparent. Apply this style to the Style property of ChartTooltipBehavior as shown in the following code example.
<chart:SfChart.Resources> <Style TargetType="Path" x:Key="tooltipStyle"> <Setter Property="Stroke" Value="Transparent"/> <Setter Property="Fill" Value="Transparent"/> </Style> </chart:SfChart.Resources> … <chart:SfChart.Behaviors> <chart:ChartTooltipBehavior Style="{StaticResource tooltipStyle}" Position="Pointer"/> </chart:SfChart.Behaviors>
Step 3: Create a custom tooltip template and assign it to the TooltipTemplate property of ChartSeries.
The following code example illustrates how to customize the chart tooltip arrow pointer background.
<chart:SfChart x:Name="Chart" Palette="BlueChrome"> <chart:SfChart.Resources> <DataTemplate x:Key="tooltipTemplate"> <Border Background="Black" Margin="0,0,0,-10" Padding="4" CornerRadius="3"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Item.Demand}" Foreground="White"/> <TextBlock Text=" : " Foreground="White" /> <TextBlock Text="{Binding Item.Year2010}" Foreground="White"/> </StackPanel> </Border> </DataTemplate> <Style TargetType="Path" x:Key="tooltipStyle"> <Setter Property="Stroke" Value="Transparent"/> <Setter Property="Fill" Value="Transparent"/> </Style> </chart:SfChart.Resources> … <chart:ColumnSeries ItemsSource="{Binding Demands}" XBindingPath="Demand" YBindingPath="Year2010" ShowTooltip="True" TooltipTemplate="{StaticResource tooltipTemplate}"/> <chart:SfChart.Behaviors> <chart:ChartTooltipBehavior Style="{StaticResource tooltipStyle}" Position="Pointer"/> </chart:SfChart.Behaviors> </chart:SfChart>
Output
The following demo image illustrates how to customize the default tooltip background in WPF Chart.
See also
How to customize the tooltip in chart
How to display the tooltip when the mouse is in any region of the FastLineBitmapSeries in WPF Charts
How to set the duration for chart tooltip
Conclusion
I hope you enjoyed learning how to customize the default tooltip background in WPF Chart.
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!