This is a migrated thread and some comments may be shown as answers.
TrackBall question
2 Answers 162 Views
This is a migrated thread and some comments may be shown as answers.
Mike
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
0
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 = @"
  <DataTemplate
     xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
     xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
   <StackPanel Orientation=""Horizontal"">
        <TextBlock Text=""Value: "" />
        <TextBlock Text=""{Binding DataPoint.Value}"" />
   </StackPanel>
 </DataTemplate>";
 
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?


Regards,
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 >>
0
Andreas
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"
                      DataBindingComplete="leftSeries_DataBindingComplete"
                      Stroke="Brown"
                      StrokeThickness="2"
                      ItemsSource="{Binding LeftSeries}"
                      ValueBinding="Value"
                      CategoryBinding="Category">
    <chartView:LineSeries.TrackBallInfoTemplate>
        <DataTemplate>
            <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" />
            </StackPanel>
        </DataTemplate>
    </chartView:LineSeries.TrackBallInfoTemplate>
</chartView:LineSeries>
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
Mike
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or