Back to Devexpress

ChartControl.Zoom Event

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-ed2862c6.md

latest5.2 KB
Original Source

ChartControl.Zoom Event

Occurs when an end-user zooms in or out of the ChartControl.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public event ChartZoomEventHandler Zoom
vb
Public Event Zoom As ChartZoomEventHandler

Event Data

The Zoom event's data class is ChartZoomEventArgs. The following properties provide information specific to this event:

PropertyDescription
AxisXGets the X-axis of the diagram point.
AxisYGets the Y-axis of the diagram point.
NewXRangeGets the new value of the AxisBase.VisualRange property for the X-axis.
NewYRangeGets the new value of the AxisBase.VisualRange property for the Y-axis.
OldXRangeGets the old value of the AxisBase.VisualRange property for the X-axis.
OldYRangeGets the old value of the AxisBase.VisualRange property for the Y-axis.
TypeGets the zoom type.

Remarks

Note that this event is raised for 2D Charts only. In 3D Charts, the similar ChartControl.Zoom3D event is raised.

Note

In the Zoom event handler, you cannot change the layout of a chart. For example, modifying the ChartControl.Series or Series.Points collection in this event may affect the axis range.

Example

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

See Also

Scroll

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace