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

CategoricalAxis LabelFormat and LabelTemplateSelector

2 Answers 440 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 09 Jun 2017, 01:40 PM

Hello,

I have a problem with the horizontal axis of my RadCartesianChar when I change the period of my statistics:

<telerik:RadCartesianChart x:Name="Chart"
                           TrackBallInfoStyle="{StaticResource ResourceKey=TrackBallInfoStyle}"
                           TrackBallLineStyle="{StaticResource ResourceKey=TransparentTrackLineStyle}"
                           helpers:ChartViewUtilities.ChartAlignmentGroup="g1">
 
    <telerik:RadCartesianChart.Resources>
        <DataTemplate x:Key="NormalTemplate">
            <TextBlock Text="{Binding}"
                       Padding="2"/>
        </DataTemplate>
        <DataTemplate x:Key="TodayTemplate">
            <Border BorderThickness="1" BorderBrush="Black">
                <TextBlock Text="{Binding}"
                           Padding="2"/>
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="HolidayTemplate">
            <TextBlock Text="{Binding}"
                       FontWeight="Bold"
                       Foreground="Red"
                       Padding="2"/>
        </DataTemplate>
        <DataTemplate x:Key="WeekendTemplate">
            <TextBlock Text="{Binding}"
                       FontWeight="Bold"
                       Foreground="Black"
                       Padding="2"/>
        </DataTemplate>
 
        <selectors:DateTypeTemplateSelector x:Key="Selector"
                                            NormalTemplate="{StaticResource NormalTemplate}"
                                            TodayTemplate="{StaticResource TodayTemplate}"
                                            HolidayTemplate="{StaticResource HolidayTemplate}"
                                            WeekendTemplate="{StaticResource WeekendTemplate}"/>
    </telerik:RadCartesianChart.Resources>
 
    <telerik:RadCartesianChart.Behaviors>
        <telerik:ChartTrackBallBehavior ShowTrackInfo="True"
                                        helpers:ChartViewUtilities.ShouldPositionTrackBallCloseToDataPoint="True"
                                        helpers:ChartViewUtilities.TrackedPointFill="{StaticResource IsMouseOverNeutralValueBrush}"
                                        helpers:ChartViewUtilities.TrackBallGroup="g1"
                                        TrackInfoUpdated="ChartTrackBallBehavior_TrackInfoUpdated"/>
    </telerik:RadCartesianChart.Behaviors>
 
    <telerik:RadCartesianChart.Grid>
        <telerik:CartesianChartGrid MajorLinesVisibility="Y" />
    </telerik:RadCartesianChart.Grid>
 
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:DateTimeCategoricalAxis LabelFormat="dd"
                                         LabelTemplateSelector="{StaticResource Selector}"/>
    </telerik:RadCartesianChart.HorizontalAxis>
 
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis SmartLabelsMode="SmartStepAndRange" MajorStep="1" />
    </telerik:RadCartesianChart.VerticalAxis>
 
    <telerik:BarSeries ItemsSource="{Binding SeaDailyStats}"
                       CategoryBinding="DateAction"
                       ValueBinding="NbAction"
                       CombineMode="Stack"
                       helpers:ChartAnimationUtilities.CartesianAnimation="Rise">
 
        <telerik:BarSeries.TrackBallInfoTemplate>
            <DataTemplate>
                <Border>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding DisplayContent, StringFormat='Mise(s) en ligne : {0}'}" />
                    </StackPanel>
                </Border>
            </DataTemplate>
        </telerik:BarSeries.TrackBallInfoTemplate>
 
        <telerik:BarSeries.DefaultVisualStyle>
            <Style TargetType="{x:Type Border}">
                <Setter Property="Background" Value="{StaticResource NeutralValueBrush}"/>
            </Style>
        </telerik:BarSeries.DefaultVisualStyle>
    </telerik:BarSeries>
 
    <telerik:BarSeries ItemsSource="{Binding SeaDailyStats}"
                       CategoryBinding="DateAction"
                       ValueBinding="Target"
                       CombineMode="Stack"
                       helpers:ChartAnimationUtilities.CartesianAnimation="Rise">
 
        <telerik:BarSeries.TrackBallInfoTemplate>
            <DataTemplate />
        </telerik:BarSeries.TrackBallInfoTemplate>
 
        <telerik:BarSeries.DefaultVisualStyle>
            <Style TargetType="Border">
                <Setter Property="Background" Value="{StaticResource BadValueBrush}"/>
            </Style>
        </telerik:BarSeries.DefaultVisualStyle>
 
    </telerik:BarSeries>
</telerik:RadCartesianChart>

 

The period is a complete month but I display only the day (dd) on horizontal axis.

The template selector allow me to display differently the type of day (normal, today, week end, holiday).

The first month all is correct but when I change the month, the SelectTemplate method of DateTypeTemplateSelector is not call again. So the template don't change with the new axis value of the month.

But if I display not only the day (dd) but the complete day (dd/MM/yyyy) on LabelFormat all works fine.

So I think that the SelectTemplate method of DateTypeTemplateSelector is call only when the displayed value is different.

But me I need o display only the day (dd).

Can you help me please. Thank you in advance and sorry for my bad English.

Kind regards,

Jonathan

2 Answers, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 09 Jun 2017, 02:11 PM
Sorry it's for WPF and not for Silverlight
0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Jun 2017, 11:23 AM
Hello Jonathan,

Thank you for contacting us.

They are calculated and drawn based on the minimum, maximum and the step of the axis (or on the number of distinct categories if the axis is categorical). This means that the LabelTemplateSelector of the axis won't listen for changes in the underlying data, but instead will listen for changes in the labels plotted on the axis.

For example, if the axis is Categorical and you insert a data point in the existing category the chart won't add new label for the axis and the label template selector won't fire, but if you add new category, there will be new label and the selector will fire to determine what template to use. That is why in your case the template selector is not fired.

To workaround this behavior you can reset every time the LabelTemplateSelector of the DateTimeCategoricalAxis when you change the collection of the chart.
(this.Chart.HorizontalAxis as DateTimeCategoricalAxis).LabelTemplateSelector = null;
(this.Chart.HorizontalAxis as DateTimeCategoricalAxis).LabelTemplateSelector = this.Chart.Resources["Selector"] as DateTypeTemplateSelector;

Hope this information is helpful.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or