This is a migrated thread and some comments may be shown as answers.

LinearAxis Maximum and ActualRange

2 Answers 52 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ioan
Top achievements
Rank 1
Ioan asked on 15 May 2014, 01:31 PM
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 Answers, 1 is accepted

Sort by
0
Ioan
Top achievements
Rank 1
answered on 16 May 2014, 10:26 AM
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;
0
Martin Ivanov
Telerik team
answered on 20 May 2014, 12:16 PM
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.
 
Tags
Chart
Asked by
Ioan
Top achievements
Rank 1
Answers by
Ioan
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or