We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Toggle multiple Axes on/off

I have a chart with 3 series, graphed from a common SfChart's SecondaryAxis.
I've been trying to figure out how I could toggle between displaying the 3 series graphed from a common SecondaryAxis and displaying the 3 series, each with their own axis.
If I add a YAxis to each series, it seems that neither setting IsEnabled = False or Visibility = Collapsed will return the series to be graphed to the common SecondaryAxis.

Any idea how I could toggle multiple axes on/off?

Thanks,
Alan

1 Reply

DA Devi Aruna Maharasi Murugan Syncfusion Team April 5, 2017 10:33 AM UTC

Hi Alan, 
  
Thanks for contacting Syncfusion Support. 
  
We have achieved your requirement (toggle between the series YAxis and chart secondary axis) with checkbox by applying null for series YAxis as shown in below code.  
  
Please find the code snippet, 
  
C# 
public partial class MainWindow : Window 
    { 
        NumericalAxis axis1; 
        NumericalAxis axis2; 
        NumericalAxis axis3; 
        public MainWindow() 
        { 
            InitializeComponent(); 
            axis1 = new NumericalAxis() 
            { 
                Interval = 10, 
                Foreground = chart.Series[0].Interior , 
                Minimum = 10, 
                ShowGridLines = false 
            }; 
            axis2 = new NumericalAxis() 
            { 
                Interval = 10, 
                Foreground = chart.Series[1].Interior, 
                Minimum = 10, 
                ShowGridLines = false 
            }; 
            axis3 = new NumericalAxis() 
            { 
                Interval = 10, 
                Foreground = chart.Series[2].Interior, 
                Minimum = 10, 
                ShowGridLines = false 
            }; 
        } 
 
        private void CheckBox_Checked(object sender, RoutedEventArgs e) 
        { 
            if(chart.SecondaryAxis.Visibility != Visibility.Visible) 
            { 
                chart.SecondaryAxis.Visibility = Visibility.Visible; 
                line1.YAxis = null; 
                line2.YAxis = null; 
                line3.YAxis = null; 
            }          
        } 
 
        private void CheckBox_Unchecked(object sender, RoutedEventArgs e) 
        { 
            chart.SecondaryAxis.Visibility = Visibility.Collapsed; 
            line1.YAxis = axis1; 
            line2.YAxis = axis2; 
            line3.YAxis = axis3; 
        } 
    } 

Please find the output screenshot, 
 
Series with chart secondary axis, 
 
  
Series with its YAxis 

 
  
We have prepared a demo sample for reference and it can be downloaded from below link, 
Sample: ToggleAxis 
  
Regards, 
Devi 





Loader.
Live Chat Icon For mobile
Up arrow icon