This is a migrated thread and some comments may be shown as answers.
Problem with LabelOffset and LabelInterval in CategoricalAxis
4 Answers 43 Views
This is a migrated thread and some comments may be shown as answers.
Janko
Top achievements
Rank 1
Janko asked on 09 Jan 2014, 03:37 PM

(I am using Telerik 2013.2.809.40 for WPF)

I have a RadCartesianChart with a Series that contains 30 items (categories are from “2013” to “2032”).


I want to show only the labels “2015”, “2020”,“2025”,“2030” in my CategoricalAxis.

How can I do this?
Setting LabelInterval=5 and LabelOffset=2
does not work (in this case only "2023" and "2028 are shown)

Thanks - Janko

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 14 Jan 2014, 01:38 PM
Hi Janko,

I assume that your categories are represented by DateTime objects, so the more appropriate approach to achieve the desired result is to use DateTimeContinuousAxis instead of CategoricalAxis. Here is an example for your particular case:

<telerik:DateTimeContinuousAxis Minimum="2015-1-1" MajorStepUnit="Year" MajorStep="5" LabelFormat="yyyy" />

The Minimum property is used to set the start date in the axis, the MajorStepUnit sets the unit that defines the custom major step of the axis, the MajorStep set the step between two adjacent ticks and the LabelFormat is used to show only the year from the DateTime.

I prepared a sample project to demonstrate this approach. Let me know whether these directions are helpful.

Regards,
Martin Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Janko
Top achievements
Rank 1
answered on 30 Jan 2014, 03:33 PM
Hi, thank you for your answer :)

I do not want to change the start date in the Axis, but I want to change the start date in the axis labels.
If I change Minimum, the values smaller then Minimum are not shown.

I attached a file to show what I would like to make.
Here the x-Axis starts at 2013, but the labels start at 2015.
0
Louis
Top achievements
Rank 1
answered on 30 Jan 2014, 10:57 PM
Hi Janko,

I wasn't able to achieve what you're trying to get with LabelInterval in any form, but I was able to do it by adapting an approach from the Financial Demo from Telerik's WPF Demo suite by using a LabelTemplate. Here are the relevant snips:

XAML:
<telerik:RadCartesianChart x:Name="Chart">
    <telerik:RadCartesianChart.Resources>
        <local:AxisLabelConverter x:Key="axisLabelConverter" />
        <DataTemplate x:Key="axisLabelTemplate">
            <TextBlock Text="{Binding Converter={StaticResource axisLabelConverter}}" />
        </DataTemplate>
    </telerik:RadCartesianChart.Resources>
    ...
    <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis LabelTemplate="{StaticResource axisLabelTemplate}" />
    </telerik:RadCartesianChart.HorizontalAxis>
    ...
</telerik:RadCartesianChart>

and the C# Converter:

public class AxisLabelConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        int number = (int)value; // Change this if your category isn't an int
        return (number % 5 == 0) ? number.ToString() : "" ;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Hope this helps!

Louis


0
Martin Ivanov
Telerik team
answered on 03 Feb 2014, 04:04 PM
Hello Janko,

Unfortunately this behavior could not be achieved out of the box. However there will be a new property for the DateTimeCategoricalAxis in our next release in the end of February. The property is called ValueAlignment and it is used in combination with the LabelInterval property.

Here is an example how the XAML for the axis should look with the new property:
<telerik:DateTimeContinuousAxis AlignmentValue="2015-1-1"
                              LabelInterval="5"
                              MajorStepUnit="Year"
                              LabelFormat="yyyy" />

You could see the result in the attached image. In the meantime I hope the approach proposed by Louis may be useful for you.

Regards,
Martin Ivanov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Asked by
Janko
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Janko
Top achievements
Rank 1
Louis
Top achievements
Rank 1
Share this question
or