Back to Devexpress

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

windowsforms-17393-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-customize-the-secondary-axis-range-when-chart-zooming-is-performed.md

latest2.0 KB
Original Source

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

  • Jun 21, 2019

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.

csharp
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));
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts

Namespace UsingZoomEvent
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub chartControl1_Zoom(ByVal sender As Object, ByVal e As ChartZoomEventArgs) Handles chartControl1.Zoom
            Dim chart As ChartControl = CType(sender, ChartControl)
            Dim diagram As XYDiagram = CType(chart.Diagram, XYDiagram)
            diagram.SecondaryAxesY(0).VisualRange.SetMinMaxValues(Convert.ToDouble(e.NewYRange.MinValue) / 2, Convert.ToDouble(e.NewYRange.MaxValue))
        End Sub
    End Class
End Namespace