Chart for WinRT > Chart Features > Axes > Annotations > Custom Labels |
To create a custom annotation using the Axis.AnnoTemplate property, use the following XAML markup or code:
XAML |
Copy Code
|
---|---|
... <Chart:ChartView.AxisX> <Chart:Axis> <Chart:Axis.Resources > <local:ColorConverter x:Key="clrcnv" /> </Chart:Axis.Resources> <Chart:Axis.AnnoTemplate> <DataTemplate> <TextBlock Width="25" TextAlignment="Center" Text="{Binding Path=Value}" Foreground="{Binding Converter={StaticResource clrcnv}}"/> </DataTemplate> </Chart:Axis.AnnoTemplate> </Chart:Axis> </Chart:ChartView.AxisX> ... |
C# |
Copy Code
|
---|---|
public class ColorConverter : IValueConverter { int cnt = 0; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { //DataPoint dpt = (DataPoint)value; // alternate the brushes return cnt++ % 2 == 0 ? Brushes.Blue : Brushes.Red; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } } |
Visual Basic |
Copy Code
|
---|---|
Public Class ColorConverter Implements IValueConverter Private cnt As Integer = 0 Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object 'DataPoint dpt = (DataPoint)value; ' alternate the brushes Return (2 = 0) End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Return Nothing End Function End Class |