This is a migrated thread and some comments may be shown as answers.
TrackBall question
2 Answers 164 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Mike asked on 15 Mar 2012, 12:16 AM
I am trying to add a trackball to a very basic RadCartesianChart. By default, the labels it adds are "Category" and "Value" in the trackball info window. Is there an easier way to change these labels than to create a TrackBallInfoTemplate for each series? I just want that header to be whatever the name of the series is...

If there is not an easy way, can someone point me to an example of adding a TrackBallInfoTemplate in C# code (as opposed to XAML).

As an aside, the reason creating TrackBallInfoTemplates is a pain for me is because I have to add LineSeries's in C# due to there not being a Series dependency property to bind to in the chart.

2 Answers, 1 is accepted

Sort by
Petar Marchev
Telerik team
answered on 19 Mar 2012, 02:21 PM
Hello Mike,

1. No, there is no other way to change these labels - the only way to achieve this is to use the track ball info template.

2. You can either have your track ball templates declared in the user control's resources find them from code behind so you can set them to the series:
var tbiTemplate = this.Resources["ATrackBallInfoTemplate"] as DataTemplate;
this.cartesianChart.Series[0].TrackBallInfoTemplate = tbiTemplate;

Or you can have the data template parsed in C# code:
string dataTemplateString = @"
   <StackPanel Orientation=""Horizontal"">
        <TextBlock Text=""Value: "" />
        <TextBlock Text=""{Binding DataPoint.Value}"" />
var tbiTemplate = System.Windows.Markup.XamlReader.Load(dataTemplateString) as DataTemplate;

3. I am not sure I understand how it would help if the Series property was a dependency property in this case. Can you explain how this would have made it easier to work with the track ball info templates?

Petar Marchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Top achievements
Rank 1
answered on 19 Apr 2012, 08:44 AM
Hey Mike!

Just had the same issue as you describe. (Almost)
Anyway, I want the label in the trackball to display the name of my selected serie.
Turned out there is a property in the LineSeries object called "DisplayName" and I want my Trackball textblock to display that text.
So I did this:

My Xaml:
<chartView:LineSeries x:Name="leftSeries"
                      ItemsSource="{Binding LeftSeries}"
            <StackPanel Background="Transparent" Orientation="Horizontal">
                <TextBlock Text="{Binding Path=DisplayHeader, FallbackValue='Left value'}" Margin="6" FontFamily="Segoe UI" Foreground="Brown" />
                <TextBlock Text=":" Margin="6" Foreground="Brown" />
                <TextBlock Text="{Binding Path=DataPoint.Value}" Margin="6" FontFamily="Segoe UI" Foreground="Brown" />
I added the event "DataBindingComplete" because the lineseries DisplayName can't data bind, so I need to take care of that in code behind.
private void leftSeries_DataBindingComplete(object sender, EventArgs e)
    if (((LineSeries)PerformanceChart.Series[1]).DataPoints.Count == 0) { return; }
    ((LineSeries)PerformanceChart.Series[1]).DisplayName = "Whatever you like it to be";

Did the trick for me.
Good luck!

Asked by
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Top achievements
Rank 1
Share this question