TrackBall question

3 posts, 0 answers
  1. Mike
    Mike avatar
    2 posts
    Member since:
    Mar 2012

    Posted 14 Mar 2012 Link to this post

    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. Petar Marchev
    Petar Marchev avatar
    1029 posts

    Posted 19 Mar 2012 Link to this post

    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 >>
  3. Andreas
    Andreas avatar
    1 posts
    Member since:
    Jul 2012

    Posted 19 Apr 2012 Link to this post

    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!

Back to Top