Set the TooltipTemplate but ToolTip didn't show.

1 Answer 66 Views
ChartView
JIJIKO
Top achievements
Rank 1
Iron
JIJIKO asked on 03 Dec 2021, 10:01 AM

Hi, guys.

I bind style to BarSeries, here is the code.

<Style TargetType="{x:Type telerik:BarSeries}">
        <Setter Property="ShowLabels" Value="True"/>
       
        <Setter Property="TooltipTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border Background="{DynamicResource BrightColor}" Padding="6" TextElement.Foreground="White">
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Y=" FontWeight="Bold" />
                                <TextBlock Text="{Binding YValue}"  />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="X=" FontWeight="Bold" />
                                <TextBlock Text="{Binding XValue}"  />
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
but ToolTip didn't show any data.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 03 Dec 2021, 11:16 AM

Hеllo JIJIKO,

The data context passed to the TooltipTemplate is an object of type DataPoint. Actually, a more concerete implementation of DataPoint, based on the used chart series. For BarSeries this will be CategoricalDataPoint and for the scatter type series (like ScatterPointSeries), this will be ScatterDataPoint. The CategoricalDataPoint doesn't have XValue and YValue properties. This is why no values are displayed in the tooltip. 

To achieve your requirement, use the Category and Value properties of CategoricalDataPoint.

<DataTemplate>
	<Border Background="{DynamicResource BrightColor}" Padding="6" TextElement.Foreground="White">
		<StackPanel>
			<StackPanel Orientation="Horizontal">
				<TextBlock Text="Y=" FontWeight="Bold" />
				<TextBlock Text="{Binding Value}"  />
			</StackPanel>
			<StackPanel Orientation="Horizontal">
				<TextBlock Text="X=" FontWeight="Bold" />
				<TextBlock Text="{Binding Category}"  />
			</StackPanel>
		</StackPanel>
	</Border>
</DataTemplate>

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ChartView
Asked by
JIJIKO
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or