Skip to main content

How to: Customize the Secondary Axis Range When Chart Zooming is Performed

This example shows how to adjust the secondary Y- axis range along which the chart is zoomed.

To accomplish this task, obtain the secondary Y-axis in the ChartControl.Zoom event handler and specify a custom secondary Y-axis range by calling the Range.SetMinMaxValues method.

using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace UsingZoomEvent {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void chartControl1_Zoom(object sender, ChartZoomEventArgs e) {
            ChartControl chart = (ChartControl)sender;
            XYDiagram diagram = (XYDiagram)chart.Diagram;
            diagram.SecondaryAxesY[0].VisualRange.SetMinMaxValues(Convert.ToDouble(e.NewYRange.MinValue) / 2,
                                                                  Convert.ToDouble(e.NewYRange.MaxValue));
        }
    }
}