Category / Section
How to apply label formatting to trackball labels in WPF Chart (SfChart)?
1 min read
You can customize the trackball label by using the TrackBallLabelTemplate property in WPF Chart (SfChart). The ChartPointInfo uses as a data context for this template. You can get the X and Y values from the ValueX and ValueY, respectively. The convertor is used where the label formatting is done for the trackball labels.
XAML
<chart:SfChart>
<chart:SfChart.Resources>
<local:LabelConverter x:Key="labelConverter"/>
<DataTemplate x:Key="trackBallTemplate">
<Border BorderBrushn="Black” BorderThickness="1”>
<Grid Height="30”>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition>
<Grid.ColumnDefinitions/>
<Rectangle Fill="White” Grid.ColumnSpan="2”/>
<Ellipse Fill="Green” Margin="3” Height="20” Width="20”/>
<TextBlock Margin="3” Grid.Column="1”>
Text="{Binding
Converter="{StaticResource labelConverter }"}"/>
<Grid/>
<Border/>
<DataTemplate/>
<chart:SfChart.Resources/>
<chart:SfChart.Behaviors>
<chart:ChartTrackBallBehavior/>
<chart:SfChart.Behaviors/>
<chart:LineSeries TrackBallLabelTemplate="{Binding trackBallTemplate}"
XBindingPath="Year" YBindingPath="Count"
ItemsSource="{Binding}"/>
<chart:SfChart/>
C#
public class LabelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var pointValue = value as ChartPointInfo;
double d = double.Parse(pointValue.ValueY.ToString());
return d.ToString("0.000000");
}
}
The following screenshot demonstrates customizing the trackball label information in which the ValueY is rounded off to six digits.
Did not find the solution
Contact Support