Adjust AxisX.LabelStep when zooming in categorical chart

4 posts, 1 answers
  1. AndrewRichards
    AndrewRichards avatar
    9 posts
    Member since:
    Oct 2011

    Posted 16 Nov 2011 Link to this post

    Hello,

    I have a data bound Chart with zooming and scrolling enabled. There are lots of points on the chart and since it's a (DateTime) categorical chart, the X axis shows a LOT of ticks. 

    chart.DefaultView.ChartArea.ZoomScrollSettingsX.MinZoomRange = range;
    chart.DefaultView.ChartArea.ZoomScrollSettingsX.RangeStart = 0.0;
    chart.DefaultView.ChartArea.ZoomScrollSettingsX.RangeEnd = range * 2;
    chart.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.ScrollAndZoom;
      
    chart.DefaultView.ChartArea.AxisX.LabelStep = 1;
    chart.DefaultView.ChartArea.AxisX.StepLabelLevelCount = 3;
    chart.DefaultView.ChartArea.AxisX.MajorGridLinesVisibility = Visibility.Visible;
    chart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "MMM yyyy";


    The problem is that when fully zoomed out (RangeStart = 0.0 and RangeEnd = 1.0), the X-axis ticker labels start to overlap. Is there an event or some other way to adjust the AxisX.LabelStep when zooming in and out ?

    I've also attached a screenshot of the problem.

    Thanks!
  2. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 21 Nov 2011 Link to this post

    Hi Andres,

    What you can do is wire to the PropertyChanged event like this:

    void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if ((RangeStart == 0.0) && (RangeEnd == 1.0))
                {
                    radChart.DefaultView.ChartArea.AxisX.LabelStep = 2;
                }
            }
    This way when your chart has RangeStart = 0.0 and RangeEnd = 1.0 values, it will set the label step to 2 or any other value that best fits your scenario.

    Kind regards,
    Peshito
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. AndrewRichards
    AndrewRichards avatar
    9 posts
    Member since:
    Oct 2011

    Posted 22 Nov 2011 Link to this post

    Not sure if I understand correctly. I have the grid on a UserControl (no access to Window). Is there an event I can listen to ?  Any other way ?
  5. Answer
    Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 24 Nov 2011 Link to this post

    Hi Andres,

    Please disregard my previous suggestion and excuse me for inconvenience caused.

    Yes, there is another way. You can wire to the ZoomScrollSettingsX PropertyChanged event like this:
    void ZoomScrollSettingsX_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if ((RangeStart == 0.0) && (RangeEnd == 1.0))
                {
                    radChart.DefaultView.ChartArea.AxisX.LabelStep = 2;
                }
            }

    Regards,
    Peshito
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top