RadCartesianChart: Labeltemplate on a DateTimeContinuousAxis: location is wrong

2 posts, 0 answers
  1. Jan
    Jan avatar
    1 posts
    Member since:
    Jun 2016

    Posted 29 Nov 2016 Link to this post

    I am trying to use a Labeltemplate on a DateTimeContinuousAxis but the texts are not located correctly on the axis. I am using the following WPF:

    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:DateTimeContinuousAxis MajorStep="{Binding CategoryAxisMajorStep}"
                                        MajorStepUnit="{Binding CategoryAxisMajorStepUnit}"
                                        LabelFitMode="Rotate">
            <telerik:DateTimeContinuousAxis.LabelTemplate>
                <DataTemplate>
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource DateTimeToStringTelerikChartMultiConverter}">
                                <Binding/>
                                <Binding Path="DataContext.DateTimeFormat"
                                    RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </telerik:DateTimeContinuousAxis.LabelTemplate>
        </telerik:DateTimeContinuousAxis>
    </telerik:RadCartesianChart.HorizontalAxis>

    The chart looks as the attached file.

    Can you help me to correctly display the labels.

     

     

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1258 posts

    Posted 01 Dec 2016 Link to this post

    Hi Jan,

    This behavior appears because the chart caches the size of the axis labels in order to optimize the performance. Basically, the labels are measured on load of the chart and their sizes are stored in memory. The multibinding kicks in after this measuring and the labels are already measured with size 0,0. As the chart arranges it elements in a canvas and the size is empty, the labels are not positioned where expected.

    In order to resolve this you can try ElementName bindin instead of RelativeSource binding in the multibinding. Or you can set MinHeight of the TextBlock in the LabelTemplate so that the size of the labels is ensured.

    Regards,
    Martin
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Back to Top