Problem with LabelOffset and LabelInterval in CategoricalAxis

5 posts, 0 answers
  1. Janko
    Janko avatar
    5 posts
    Member since:
    Sep 2012

    Posted 09 Jan 2014 Link to this post

    (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

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 14 Jan 2014 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Janko
    Janko avatar
    5 posts
    Member since:
    Sep 2012

    Posted 30 Jan 2014 in reply to Martin Link to this post

    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.
  5. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 30 Jan 2014 in reply to Janko Link to this post

    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


  6. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 03 Feb 2014 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready