This is a migrated thread and some comments may be shown as answers.

Show category labels in Tooltip

1 Answer 108 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 14 Jun 2018, 12:48 PM

Hi Telerik,

I'm writing an app that is basically showing a pivot grid with a RadChartView on it.  I'm using the "Rad Chart View Integration" as an example.

How do I make the tooltips show the column names and not just their values?

I'm attaching a screenshot showing what I have and what I want.

 

Thanks so much!

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jun 2018, 12:29 PM
Hello Tony,

To achieve your requirement you can dig into the DataProvider of the PivotChartViewModel and link the provided values to the column/row descriptors. Here is an example in code:
<telerik:RadCartesianChart.TooltipTemplate>
    <DataTemplate>
        <Grid>
            <Path Data="M-1236,-441 L-1180,-441 -1180,-424 -1228,-424 -1230.5,-420 -1233,-424 -1236,-424 z" Stretch="Fill" Fill="{telerik:Windows8Resource ResourceKey=MainBrush}" Stroke="{telerik:Windows8Resource ResourceKey=AccentBrush}" StrokeThickness="2"/>
            <StackPanel Orientation="Vertical" Margin="5,5,5,18">
                <ContentControl>
                    <ContentControl.Content>
                        <MultiBinding Converter="{StaticResource ToolTipContentConverter}">
                            <Binding Path="Presenter" />
                            <Binding Path="DataItem" />
                        </MultiBinding>                                       
                    </ContentControl.Content>
                </ContentControl>
            </StackPanel>
        </Grid>
    </DataTemplate>
</telerik:RadCartesianChart.TooltipTemplate>

public class ToolTipContentConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        var series = (CartesianSeries)values[0];
        var chart = series.Chart;
        var chartModel = (PivotChartViewModel)chart.DataContext;
        var provider = (LocalDataSourceProvider)chartModel.DataProvider;
 
        var chartItem = (PivotChartItem)values[1];
 
        var rootStackPanel = new StackPanel();
 
        var xNames = chartItem.NameX.Split(';');
        for (int i = 0; i < xNames.Count(); i++)
        {
            var stackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
             
            var name = xNames[i];
            var descriptor = provider.RowGroupDescriptions[i];
 
            stackPanel.Children.Add(new TextBlock() { Text = descriptor.DisplayName + ": " });
            stackPanel.Children.Add(new TextBlock() { Text = name });
            rootStackPanel.Children.Add(stackPanel);
        }
 
        var yNames = chartItem.NameY.Split(';');
        for (int i = 0; i < yNames.Count(); i++)
        {
            var stackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
 
            var name = yNames[i];
            var descriptor = provider.ColumnGroupDescriptions[i];
 
            stackPanel.Children.Add(new TextBlock() { Text = descriptor.DisplayName + ": " });
            stackPanel.Children.Add(new TextBlock() { Text = name });
            rootStackPanel.Children.Add(stackPanel);
        }
 
        var valueStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
        valueStackPanel.Children.Add(new TextBlock() { Text = provider.AggregateDescriptions[0].DisplayName + ": " });
        valueStackPanel.Children.Add(new TextBlock() { Text = chartItem.Value.ToString() });
        rootStackPanel.Children.Add(valueStackPanel);
 
        return rootStackPanel;           
    }
 
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Tony
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or