Collapsing DateTimeCategoricalAxis still reserves space

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

    Posted 13 May 2014 Link to this post

    I have a problem where collapsing a DateTimeCategoricalAxis is still reserving space in the UI. It is being used as the Horizontal axis, and is reserving Width but not Height. The below example shows the problem. 

    Note that the display looks correct initially, with both graphs going to the edge of the windows. Now use the checkbox to enable the horizontal display on the bottom chart, which switches the Visibility on the Axis from Collapsed to Visible. The chart displays correctly. Now uncheck the checkbox, which changes the Visibility back to Collapsed. Now notice the chart has about an inch of white-space on either side of the graph. The Height collapsed correctly, but the Width did not.

    Is there any way of getting the Axis to resize correctly after being Collapsed short of replacing the Axis completely (see the commented code)?

    This was tested with 2014.1.331.45.

    Thanks,
    Louis

    MainWindow.xaml:
    <Window x:Class="CollapsedAxis.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    Title="MainWindow" Height="400" Width="600">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <telerik:RadCartesianChart x:Name="PropertyChart1" Grid.Row="0">
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:DateTimeCategoricalAxis Visibility="Collapsed"/>
                </telerik:RadCartesianChart.HorizontalAxis>
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis Visibility="Collapsed"/>
                </telerik:RadCartesianChart.VerticalAxis>
                <telerik:RadCartesianChart.Series>
                    <telerik:LineSeries
                           CategoryBinding="Date"
                           ValueBinding="Value"
                           ItemsSource="{Binding Path=Series1}">
                    </telerik:LineSeries>
                </telerik:RadCartesianChart.Series>
            </telerik:RadCartesianChart>
            <telerik:RadCartesianChart x:Name="PropertyChart2" Grid.Row="1">
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:DateTimeCategoricalAxis Visibility="{Binding Path=AxisVisible}"/>
                </telerik:RadCartesianChart.HorizontalAxis>
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis Visibility="{Binding Path=AxisVisible}"/>
                </telerik:RadCartesianChart.VerticalAxis>
                <telerik:RadCartesianChart.Series>
                    <telerik:LineSeries
                           CategoryBinding="Date"
                           ValueBinding="Value"
                           ItemsSource="{Binding Path=Series1}">
                    </telerik:LineSeries>
                </telerik:RadCartesianChart.Series>
            </telerik:RadCartesianChart>
            <CheckBox Grid.Row="2" IsChecked="{Binding Path=DisplayAxis}" Content="Display Axis" HorizontalAlignment="Left"/>
        </Grid>
    </Window>

    MainWindow.xaml.cs:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Data;
    using Telerik.Windows.Controls.ChartView;
     
    namespace CollapsedAxis
    {
        public class MyPoint
        {
            public DateTime Date { get; set; }
            public Double Value { get; set; }
        }
        public partial class MainWindow : Window, INotifyPropertyChanged
        {
            public List<MyPoint> Series1 { get; private set; }
     
            private bool _DisplayAxis;
            public bool DisplayAxis
            {
                get { return _DisplayAxis; }
                set
                {
                    _DisplayAxis = value;
                    AxisVisible = (_DisplayAxis ? Visibility.Visible : Visibility.Collapsed);
                    RaisePropertyChanged("DisplayAxis");
                }
            }
     
            private Visibility _AxisVisible;
            public Visibility AxisVisible
            {
                get { return _AxisVisible; }
                set
                {
                    _AxisVisible = value;
                    // Enabling this to replace the axis instead of just using the binding to
                    // collapse it results in the correct behavior.
                    //PropertyChart2.HorizontalAxis = new DateTimeCategoricalAxis() { Visibility = _AxisVisible };
                    RaisePropertyChanged("AxisVisible");
                }
            }
     
            public MainWindow()
            {
                Series1 = new List<MyPoint>();
                _DisplayAxis = false;
                _AxisVisible = Visibility.Collapsed;
                for (int i = 0; i < 5; i++)
                {
                    DateTime date = DateTime.Today.AddDays(i);
                    Series1.Add(new MyPoint() { Date = date, Value = i * 1000 });
                }
                InitializeComponent();
                DataContext = this;
            }
            #region INotifyPropertyChanged
            public event PropertyChangedEventHandler PropertyChanged;
            protected void RaisePropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion
        }
    }

  2. Peshito
    Admin
    Peshito avatar
    496 posts

    Posted 14 May 2014 Link to this post

    Hello Louis,

    Thank you for the detailed explanation and sharing the code for reproducing the issue. It helped me in finding out what the issue is. Actually there is a bug when the axis visibility is changed at runtime. The bug is logged in our feedback portal and you can monitor its progress and vote for it using the link below:
    http://feedback.telerik.com/Project/143/Feedback/Details/128189-chartview-runtime-axis-visibility-change-does-not-properly-update-charts-size

    I cannot suggest another workaround at that moment different than the one you have already found.

    Thank you for bringing this to our attention. As a gratitude to this finding your Telerik points are now updated.

    Regards,
    Peshito
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 15 May 2014 in reply to Peshito Link to this post

    Thank you Peshito. 

    I'm a bit confused by the voting on bugs, however. I understand voting for new features, but shouldn't bugs be proactively addressed in upcoming releases?

    I've since found that while my solution works for the main chart axes, it does not work if series are assigned their own custom Axis. Recreating these axes does not remove the extra space, so this is now a visual problem in our application that I don't have a work-around for. Any ideas?

    Thanks,
    Louis
  5. Peshito
    Admin
    Peshito avatar
    496 posts

    Posted 19 May 2014 Link to this post

    Hi,

    Voting on a bug does not mean that it will or will not be fixed depending on the collected votes. Voting will raise the bug's priority and the possibility to be fixed faster for an upcoming release or LIB.

    The issue having series assigned their own axes is connected with the one already logged in and should also be fixed once the fix is done.

    Please excuse us for the inconvenience caused.

    Regards,
    Peshito
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top