LinearAxis Maximum and ActualRange

3 posts, 0 answers
  1. Ioan
    Ioan avatar
    34 posts
    Member since:
    Dec 2012

    Posted 15 May 2014 Link to this post

    I have a chart with 3 BarSeries and each one can be hidden. The problem occurs when I hide the BarSerie with the biggest value. The LinearAxis does not rescale and keeps the maximum. ActualRange.Maximum cannot be set, and LinearAxis.Maximum has no effect. Is there a way to reset ActualRange whenever I hide a BarSerie?
    https://dl.dropboxusercontent.com/u/26902722/TelerikCharts.zip
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using Telerik.Charting;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.Charting;
    using Telerik.Windows.Controls.ChartView;
    using TelerikCharts.Internal;
     
    namespace TelerikCharts
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                DataContext = new TelerikChartsTestsModel() { refChart = chart,refLinearAxis = linearAxis};
            }
        }
     
        public class TelerikChartsTestsModel : BusyBase
        {
            public RadCartesianChart refChart;
            public LinearAxis refLinearAxis;
            //data
            #region
            List<ConsumptionDay> _consumptionDaysWeek1=new List<ConsumptionDay>()
            {
                {new ConsumptionDay(){Day="Monday",Value=10}},
                {new ConsumptionDay(){Day="Tuesday",Value=20}},
                {new ConsumptionDay(){Day="Wednesday",Value=15}},
                {new ConsumptionDay(){Day="Thursday",Value=30}},
                {new ConsumptionDay(){Day="Friday",Value=25}},
                {new ConsumptionDay(){Day="Saturday",Value=13}},
                {new ConsumptionDay(){Day="Sunday",Value=14}},
            };
     
            List<ConsumptionDay> _consumptionDaysWeek2 = new List<ConsumptionDay>()
            {
                {new ConsumptionDay(){Day="Monday",Value=20}},
                {new ConsumptionDay(){Day="Tuesday",Value=40}},
                {new ConsumptionDay(){Day="Wednesday",Value=30}},
                {new ConsumptionDay(){Day="Thursday",Value=60}},
                {new ConsumptionDay(){Day="Friday",Value=50}},
                {new ConsumptionDay(){Day="Saturday",Value=26}},
                {new ConsumptionDay(){Day="Sunday",Value=28}},
            };
     
            List<ConsumptionDay> _consumptionDaysWeek3 = new List<ConsumptionDay>()
            {
                {new ConsumptionDay(){Day="Monday",Value=30}},
                {new ConsumptionDay(){Day="Tuesday",Value=60}},
                {new ConsumptionDay(){Day="Wednesday",Value=45}},
                {new ConsumptionDay(){Day="Thursday",Value=90}},
                {new ConsumptionDay(){Day="Friday",Value=75}},
                {new ConsumptionDay(){Day="Saturday",Value=39}},
                {new ConsumptionDay(){Day="Sunday",Value=42}},
            };
     
     
     
            #endregion
            private bool _consumptionDaysWeek1Enabled;
            private bool _consumptionDaysWeek2Enabled;
            private bool _consumptionDaysWeek3Enabled;
            private double _maximum=double.PositiveInfinity;
            private ChartSeriesCombineMode _barCombineMode = ChartSeriesCombineMode.Cluster;
            public TelerikChartsTestsModel()
            {
                 
            }
     
            public double Maximum
            {
                get { return _maximum; }
                set
                {
                    _maximum = value;
                    OnPropertyChanged("Maximum");
                }
            }
            public bool ConsumptionDaysWeek1Enabled
            {
                get { return _consumptionDaysWeek1Enabled; }
                set
                {
                    _consumptionDaysWeek1Enabled = value;
                    OnPropertyChanged("ConsumptionDaysWeek1Enabled");
                }
            }
            public bool ConsumptionDaysWeek2Enabled
            {
                get { return _consumptionDaysWeek2Enabled; }
                set
                {
                    _consumptionDaysWeek2Enabled = value;
                    OnPropertyChanged("ConsumptionDaysWeek2Enabled");
                }
            }
            public bool ConsumptionDaysWeek3Enabled
            {
                get { return _consumptionDaysWeek3Enabled; }
                set
                {
                    _consumptionDaysWeek3Enabled = value;
                    OnPropertyChanged("ConsumptionDaysWeek3Enabled");
                }
            }
            public List<ConsumptionDay> ConsumptionDaysWeek1
            {
                get { return _consumptionDaysWeek1; }
                set
                {
                    _consumptionDaysWeek1 = value;
                    OnPropertyChanged("ConsumptionDaysWeek1");
                }
            }
            public List<ConsumptionDay> ConsumptionDaysWeek2
            {
                get { return _consumptionDaysWeek2; }
                set
                {
                    _consumptionDaysWeek2 = value;
                    OnPropertyChanged("ConsumptionDaysWeek2");
                }
            }
            public List<ConsumptionDay> ConsumptionDaysWeek3
            {
                get { return _consumptionDaysWeek3; }
                set
                {
                    _consumptionDaysWeek3 = value;
                    OnPropertyChanged("ConsumptionDaysWeek3");
                }
            }
            public ChartSeriesCombineMode BarCombineMode
            {
                get
                {
                    return this._barCombineMode;
                }
                set
                {
                    _barCombineMode = value;
                    OnPropertyChanged("BarCombineMode");
                }
            }
     
        }
     
        public class ConsumptionDay
        {
            public string Day { get; set; }
            public int Value { get; set; }
        }
    }

    <UserControl x:Class="TelerikCharts.MainPage"
            xmlns:converters="clr-namespace:TelerikCharts.Converters"
            mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <UserControl.Resources>
            <converters:BoolVisibility x:Key="BoolVisibility" />
            <converters:BoolCombineModeCluster x:Key="BoolCombineModeCluster" />
            <telerik:BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot">
     
                <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <!--<ColumnDefinition Width="*"></ColumnDefinition>-->
            </Grid.ColumnDefinitions>
             
            <telerik:RadCartesianChart  x:Name="chart" Palette="Metro"   >
                <telerik:RadCartesianChart.Series>
                    <telerik:BarSeries
                        CategoryBinding="Day"
                        ValueBinding="Value"
                        Visibility="{Binding ConsumptionDaysWeek1Enabled, Converter={StaticResource VisibilityOfBool}}"
                        IsEnabled="{Binding ConsumptionDaysWeek1Enabled}"
                        CombineMode="{Binding Path=ConsumptionDaysWeek1Enabled, Converter={StaticResource BoolCombineModeCluster}}"
                        ItemsSource="{Binding ConsumptionDaysWeek1}">
                    </telerik:BarSeries>
                    <telerik:BarSeries
                        CategoryBinding="Day"
                        ValueBinding="Value"
                        Visibility="{Binding ConsumptionDaysWeek2Enabled, Converter={StaticResource VisibilityOfBool}}"
                        IsEnabled="{Binding ConsumptionDaysWeek2Enabled}"
                        CombineMode="{Binding Path=ConsumptionDaysWeek2Enabled, Converter={StaticResource BoolCombineModeCluster}}"
                        ItemsSource="{Binding ConsumptionDaysWeek2}">
                    </telerik:BarSeries>
                    <telerik:BarSeries
                        CategoryBinding="Day"
                        ValueBinding="Value"
                        Visibility="{Binding ConsumptionDaysWeek3Enabled, Converter={StaticResource VisibilityOfBool}}"
                        IsEnabled="{Binding ConsumptionDaysWeek3Enabled}"
                        CombineMode="{Binding Path=ConsumptionDaysWeek3Enabled, Converter={StaticResource BoolCombineModeCluster}}"
                        ItemsSource="{Binding ConsumptionDaysWeek3}">
                    </telerik:BarSeries>
                </telerik:RadCartesianChart.Series>
                 
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:CategoricalAxis></telerik:CategoricalAxis>
                </telerik:RadCartesianChart.HorizontalAxis>
                 
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis x:Name="linearAxis" />
                </telerik:RadCartesianChart.VerticalAxis>
                 
            </telerik:RadCartesianChart>
            <StackPanel
                Grid.Column="1"
                Orientation="Vertical">
                <CheckBox
                    IsChecked="{Binding ConsumptionDaysWeek1Enabled, Mode=TwoWay}">
                    <TextBlock
                        Text="ConsumptionDaysWeek1"/>
                </CheckBox>
                <CheckBox
                    IsChecked="{Binding ConsumptionDaysWeek2Enabled, Mode=TwoWay}">
                    <TextBlock
                        Text="ConsumptionDaysWeek2"/>
                </CheckBox>
                <CheckBox
                    IsChecked="{Binding ConsumptionDaysWeek3Enabled, Mode=TwoWay}">
                    <TextBlock
                        Text="ConsumptionDaysWeek3"/>
                </CheckBox>
            </StackPanel>
        </Grid>
    </UserControl>
  2. Ioan
    Ioan avatar
    34 posts
    Member since:
    Dec 2012

    Posted 16 May 2014 Link to this post

    Found a fix, not very elegant, but it works.
    To trigger update on ActualRange values, I update the ItemsSource value with null (if disabled) or the list (if enabled)
    refChart.Series[0,1 or 2].ItemsSource = enabled ? ConsumptionList : null;
  3. DevCraft banner
  4. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 20 May 2014 Link to this post

    Hello Ioan,

    Note that after the series data points are plotted on the chart even if you set the Visibility of the series to Collapsed, this series won't be removed and therefore the axis won't change its range. This is why in order to change the axis range you will need to remove the ItemsSource of the series or the series itself.

    Regards,
    Martin
    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