MajorTickInterval trouble when Zooming

6 posts, 1 answers
  1. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 10 Jan 2014 Link to this post

    I'm trying to dynamically adjust the tick marks and labels on a RadCartesianChart using MajorTickInterval and LabelInterval when zooming to maintain an acceptable look. However, the chart does not maintain the specified MajorTickInterval when zooming, and I haven't been able to figure out the specifics of the behavior to adjust accordingly.

    Here's a simple example to illustrate.

    XAML:
    <Window x:Class="ZoomMajorTickInterval.MainWindow"
            Title="MainWindow" Height="350" Width="1280">
        <Grid>
            <telerik:RadCartesianChart x:Name="Chart">
                <telerik:RadCartesianChart.Grid>
                    <telerik:CartesianChartGrid MajorLinesVisibility="XY" />
                </telerik:RadCartesianChart.Grid>
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:CategoricalAxis LabelFitMode="Rotate" />
                </telerik:RadCartesianChart.HorizontalAxis>
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis/>
                </telerik:RadCartesianChart.VerticalAxis>
                <telerik:RadCartesianChart.Behaviors>
                    <telerik:ChartPanAndZoomBehavior ZoomMode="Both" PanMode="Both" />
                </telerik:RadCartesianChart.Behaviors>
                <telerik:RadCartesianChart.Series>
                    <telerik:LineSeries ItemsSource="{Binding MyData}" CategoryBinding="PeriodText" ValueBinding="DataValue" />
                </telerik:RadCartesianChart.Series>
            </telerik:RadCartesianChart>
        </Grid>
    </Window>

    Code-behind:
    using System;
    using System.Windows;
    using System.Collections.ObjectModel;
    using Telerik.Windows.Controls.ChartView;
    namespace ZoomMajorTickInterval
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                Random r = new Random();
                MyData = new ObservableCollection<DataPoint>();
                for (int ctr = 0; ctr < 500; ctr++)
                    MyData.Add(new DataPoint() { PeriodText = "Q" + ctr.ToString(), DataValue = r.Next(1000) });
                DataContext = this;
                CategoricalAxis axis = Chart.HorizontalAxis as CategoricalAxis;
                axis.MajorTickInterval = 5;
                Chart.HorizontalAxis.LabelInterval = 2;
            }
            public ObservableCollection<DataPoint> MyData { get; set; }
        }
        public class DataPoint
        {
            public string PeriodText {get; set;}
            public int DataValue { get; set; }
        }
    }

    Run the example and notice that initially it correctly renders major ticks every 5 data points, and labels every 2 major ticks, just as specified in the code. This displays 50 labels. Now move the max zoom slider on the horizontal axis back to about the 2/3 mark and the axis shifts from using 5 points between major ticks to 2. The labels continue to show every 2 major ticks, so now it is displaying 81 labels, which is much more crowded than desired (even more-so in my real application).

    Even more problematically, the value of MajorTickInterval remains 5 even though the display has changed, so I have no way to re-calculate the LabelInterval appropriately to maintain the number of labels I want.

    Is this a bug, or is there an algorithm at work here? If the latter, how can I determine what the interval actually is to adjust the labels correctly?

    I'm using the 2013 1204 build.

    Thanks,
    Louis

  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 15 Jan 2014 Link to this post

    Hello Louis,

    You are right that the MajorTickInterval property of the CategoricalAxis is updated according to the current zoom factor. Unfortunately, there is no an easy way to restrict the charting component to recalculate the value of the property.

    Please accept our apology for the inconvenience caused.

    Regards,
    Pavel R. Pavlov
    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. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 15 Jan 2014 Link to this post

    Thanks for the response Pavel. Is there any way to programatically retrieve the actual value so that the LabelInterval can be set appropriately? Is there a bug report/feature request to remedy this in a future release?

    In the absence of a way to retrieve the actual value, can you provide the algorithm used such that I can figure out what the value will be to accommodate?

    Thanks,
    Louis
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 20 Jan 2014 Link to this post

    Hello Louis,

    This is actually a built-in feature of the RadChartView control. Most of our clients find it very useful when the axis adjusts the tick interval so that when you zoom in, more detailed information is displayed.

    I have attached a simple project to demonstrate how you can adaptively set the MajorTickInterval property of the CategoricalAxis so that you will override the internal adaptive logic of the charting component.

    Please take a look at the attached project and let us know if it works in your particular scenario.

    Regards,
    Pavel R. Pavlov
    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 >>
  6. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 20 Jan 2014 Link to this post

    That is exactly what I needed, thank you Pavel.

    I understand the usefulness of the adjusting axis, but my problem is that the LabelInterval is not automatically scaled with it, resulting in the crowded look shown in my example. It would be nice if you could set a value for target number of labels and ticks, and have the chart adjust both the tick interval and label interval to accommodate. Maybe something for a future release? ;)

    Your example, however, allowed me to manually adjust these values in code-behind, and thus solves my problem for now. Thanks again!

    Louis
  7. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 23 Jan 2014 Link to this post

    Hi Louis,

    Thank you for your valuable feedback. Please note that you can suggest a feature request in our feedback portal. Once logged in the portal we will evaluate your suggestion and if approved we will implement that feature in our future releases.

    Regards,
    Pavel R. Pavlov
    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