This is a migrated thread and some comments may be shown as answers.

I can't set ChartAnnotationLabelDefinition.Template.

2 Answers 178 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 03 Oct 2016, 10:03 AM

Hello. I try to set ChartAnnotationLabelDefinition.Template in the way where the label of annotation has red color. But I havn't got the required result yet. I wrote the following XAML markup:

<telerik:RadCartesianChart Visibility="{Binding IsAbsoluteBarChartVisible}">
            <!--The definition of an annotation line-->
            <telerik:RadCartesianChart.Annotations>
                <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis}" Value="{Binding AnnotationValue}" Label="{Binding AnnotationLabel}" Stroke="Red" StrokeThickness="2" DashArray="8 2">
                    <telerik:CartesianGridLineAnnotation.LabelDefinition>
                        <telerik:ChartAnnotationLabelDefinition Location="Inside"  VerticalAlignment="Bottom"  HorizontalAlignment="Center">
                            <!--HERE IS THE TEMPLATE DEFINITION-->
                            <telerik:ChartAnnotationLabelDefinition.Template>
                                <DataTemplate>
                                    <TextBlock Foreground="Red" FontWeight="DemiBold"/>
                                </DataTemplate>
                            </telerik:ChartAnnotationLabelDefinition.Template>
                        </telerik:ChartAnnotationLabelDefinition>
                    </telerik:CartesianGridLineAnnotation.LabelDefinition>
                </telerik:CartesianGridLineAnnotation>
            </telerik:RadCartesianChart.Annotations>
            <!-- X axis-->
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:CategoricalAxis/>
            </telerik:RadCartesianChart.HorizontalAxis>
            <!-- Y axis-->
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis x:Name="verticalAxis" Title="Децибелы [Дб]" Minimum="{Binding ChartMinimum}" Maximum="{Binding ChartMaximum}" MajorStep="{Binding CurrentStep}"/>
            </telerik:RadCartesianChart.VerticalAxis>
            <!--The chart itself-->
            <telerik:RadCartesianChart.Series>
                <telerik:BarSeries ShowLabels="True" CategoryBinding="Category" ValueBinding="Value" ItemsSource="{Binding Data}"/>
            </telerik:RadCartesianChart.Series>
        </telerik:RadCartesianChart>

But when I run my application and navigate to the View where charts are displayed then I see only annotation without label (please see 'AnnotationWithoutLabels.PNG' file attached). When I comment the following part of XAML markup

<telerik:ChartAnnotationLabelDefinition.Template>
    <DataTemplate>
        <TextBlock Foreground="Red" FontWeight="DemiBold"/>
    </DataTemplate>
</telerik:ChartAnnotationLabelDefinition.Template>

then I see annotation with black colored label (please see 'AnnotationWithBlackColoredLabel.PNG' file attached). How do I get a bright red color for the annotation label?

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 04 Oct 2016, 09:33 AM
Hello Yaroslav,

The label is not displayed when you set the Template property, because the TextBlock inside the DataTemplate doesn't have its Text property set. 
<telerik:ChartAnnotationLabelDefinition.Template>
    <DataTemplate>
        <TextBlock Text="{Binding}" Foreground="Red" FontWeight="DemiBold"/>
    </DataTemplate>
</telerik:ChartAnnotationLabelDefinition.Template>
Note that the data context passed in the template is the value of the annotation's Label property.

If you don't want to use a template you can achieve the same result by setting the DefaultVisualStyle instead of the Template property.
<telerik:ChartAnnotationLabelDefinition.DefaultVisualStyle>
    <Style TargetType="TextBlock">
        <Setter Property="Foreground" Value="Red" />
    </Style>
</telerik:ChartAnnotationLabelDefinition.DefaultVisualStyle>

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Dmitry
Top achievements
Rank 1
answered on 05 Oct 2016, 05:57 AM
Martin, fthank you for your help.
Tags
ChartView
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or