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

RadCartesianChart: Labeltemplate on a DateTimeContinuousAxis: location is wrong

1 Answer 118 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 29 Nov 2016, 07:18 AM

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 01 Dec 2016, 05:23 PM
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.
Tags
ChartView
Asked by
Jan
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or