Articles in this section
Category / Section

How to customize the Tooltip in WPF SfChart?

2 mins read

Description

Tooltip in WPF SfChart offer a variety of customization options that help us to visualize the chart with more flexibility and information. Let’s address some of the most frequently asked questions regarding tooltip customizations.

  • How to enable tooltip for chart
  • How to apply template for tooltip
  • How to format the text in the tooltip
  • How to add an image in the tooltip
  • How to add a chart inside tooltip

Default tooltip


Tooltip can be enabled by setting the ShowTooltip property of ChartSeries to true. By default, the tooltip displays the y-value of the hovered ChartSegment.


Code snippet

<chart:SfChart>
    …
    <chart:ColumnSeries XBindingPath="XValue"                             
                                      YBindingPath="YValue"
                                      ItemsSource="{Binding Data}" 
                                      ShowTooltip="True" >
    </chart:ColumnSeries>
</chart:SfChart>

Output

Default Tooltip of Chart.

Applying template for tooltip


You can apply a custom tooltip template by setting the TooltipTemplate property of ChartSeries. The DataContext of the tooltip is the data item corresponding to the hovered ChartSegment.


Code snippet

    <chart:ColumnSeries>
        <chart:ColumnSeries.TooltipTemplate>
            <DataTemplate>
                <Border Background="White" Padding="4" BorderThickness="1" BorderBrush="Black">
                    <StackPanel Orientation="Vertical" >
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="X Value: " />
                            <TextBlock Text="{Binding Item.XValue}" HorizontalAlignment="Right"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Y Value: " />
                            <TextBlock Text="{Binding Item.YValue}" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </chart:ColumnSeries.TooltipTemplate>
    </chart:ColumnSeries>

Output

Chart with Tooltip Template.

Formatting tooltip content


The tooltip content can be formatted by using string formatting on the text elements used in TooltipTemplate.


Code snippet

<chart:ColumnSeries.TooltipTemplate>
    <DataTemplate>
        <Border Background="White" Padding="4" BorderThickness="1" BorderBrush="Black">
            <TextBlock Text="{Binding Path=Item.YValue, StringFormat='{}{0:c}'}"
                                 HorizontalAlignment="Right"/>
        </Border>
    </DataTemplate>
</chart:ColumnSeries.TooltipTemplate>

Output

Chart with formatted tooltip text.


Adding image for tooltip content


Image can be set to tooltip content by defining an Image element within the TooltipTemplate.


Code snippet

<chart:ColumnSeries.TooltipTemplate>
    <DataTemplate >
        <Border BorderBrush="Black" BorderThickness="1">
         …
         <Image Grid.RowSpan="2" Grid.Column="0" HorizontalAlignment="Left" Margin="3" 
                       Source="{Binding Item.ImagePath}" ></Image>
        </Border>
    </DataTemplate>
</chart:ColumnSeries.TooltipTemplate>

Output

Chart tooltip with image.

Adding chart in tooltip content


You can embed another chart within a tooltip as tooltip content by defining an SfChart inside TooltipTemplate.


Code snippet

<chart:ColumnSeries.TooltipTemplate>
    <DataTemplate>
        <chart:SfChart AreaBorderThickness="0"  Width="250" Height="150"
                                  Background="White" BorderBrush="Black" BorderThickness="1" >
            <chart:SfChart.Header>
                <TextBlock Text="Reports in quarters" FontSize="15" FontWeight="Bold"
                                     Margin="0,6,0,0"/>
            </chart:SfChart.Header>
            <chart:PieSeries XBindingPath="Month" YBindingPath="Sales"
                                         ItemsSource="{Binding  Item.InternalData}"                                                 
                                         LabelPosition="OutsideExtended">
                <chart:PieSeries.AdornmentsInfo>
                    <chart:ChartAdornmentInfo ShowLabel="True" ShowConnectorLine="True" />
                </chart:PieSeries.AdornmentsInfo>
            </chart:PieSeries>
        </chart:SfChart>
    </DataTemplate>
</chart:ColumnSeries.TooltipTemplate>

Output

Chart added as a tooltip content for another chart.


Conclusion

I hope you enjoyed learning about how to customize the tooltip in chart.

You can refer to our  WPF Chart feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Chart documentation 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 forumsDirect-Trac, 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