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:
MainWindow.xaml.cs:
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: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 }}