setting ZoomMode programatically doesn't work!

Hi, 
I have two check boxes in my application  called xAxisCheckbox and yAxisCheckbox and when the x checkbox is checked I want the zoom mode to be set to just X axis and the same functionality for y checkbox, when I check one of the checkboxes for the first time it works fine but as soon as I check the other checkbox the zoomMode gets set to XY, and it just remains like that, here is the checked code snippet:
Could you please help me with this issue?

        private void XAxis_Checked(object sender, EventArgs e)
        {
            Checkbox x = sender as Checkbox;
            if (x.IsChecked)
            {
                yAxisCheckbox.IsChecked = false;
                mainChart.ChartBehaviors.Add(new ChartZoomPanBehavior()
                {
                    ZoomMode = ZoomMode.X
                });
            }
        }

        private void YAxis_Checked(object sender, EventArgs e)
        {
            Checkbox y = sender as Checkbox;
            if (y.IsChecked)
            {
                xAxisCheckbox.IsChecked = false;
                mainChart.ChartBehaviors.Add(new ChartZoomPanBehavior()
                {
                    ZoomMode = ZoomMode.Y
                });
            }
         }


3 Replies

MP Michael Prabhu M Syncfusion Team July 16, 2018 09:30 AM UTC

Hi Reihaneh, 
 
We have analyzed your code snippet and found that you are adding a new ChartZoomPanBehavior every time the checkbox is checked, and this is not required, you can add the zoom pan behavior once and changing the zoommode with respect to check box will achieve your requirement. You can follow the below code snippet for your reference. 
 
Code Snippet C# 
ChartZoomPanBehavior behavior; 
        public ChartSample() 
        { 
            InitializeComponent(); 
            behavior = new ChartZoomPanBehavior() 
            { 
                EnableZooming = false 
            }; 
            mainChart.ChartBehaviors.Add(behavior); 
        } 
         
        private void xAxisCheckbox_StateChanged(object sender, StateChangedEventArgs e) 
        { 
            var switchBox = sender as SfCheckBox; 
            if (switchBox.IsChecked == true) 
            { 
                yAxisCheckbox.IsChecked = false; 
                behavior.ZoomMode = ZoomMode.X; 
                behavior.EnableZooming = true; 
            } 
            else 
                behavior.EnableZooming = false; 
        } 
 
        private void yAxisCheckbox_StateChanged(object sender, StateChangedEventArgs e) 
        { 
            var switchBox = sender as SfCheckBox; 
            if (switchBox.IsChecked == true) 
            { 
                xAxisCheckbox.IsChecked = false; 
                behavior.ZoomMode = ZoomMode.Y; 
                behavior.EnableZooming = true; 
            } 
            else 
                behavior.EnableZooming = false; 
        } 
 
 
 
We have also prepared a sample based on this and the sample can be downloaded from the link below. 
 
Sample: 138716
 
 
Let us know if you need any other assistance on this.  
Thanks, 
Michael 




RK Reihaneh Khaksaran July 21, 2018 08:14 AM UTC

Thank you so much for your great support, it worked perfectly fine. Thanks a lot.
Best regards,
Reihaneh


MP Michael Prabhu M Syncfusion Team July 23, 2018 04:54 AM UTC

Hi Reihaneh, 
 
Glad we could help, feel free to contact us any time if you need any other assistance.  
 
Thanks, 
Michael 



Loader.
Up arrow icon