[]
        
(Showing Draft Content)

Creating a Zoom Effect

To create a zoom effect with the chart, simply adjust the axis. For example, you can add two button controls (Zoom in and Zoom out buttons) to your application which will adjust the axis at run time when each is pressed. Here is a code example showing how to handle the Button_Click events to control zooming:

To write code in Visual Basic

' Controls zooming in      
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
    Dim xMin As Double = Me.C1Chart1.ChartArea.AxisX.Min
    Dim xMax As Double = Me.C1Chart1.ChartArea.AxisX.Max 
    Dim xChange As Double = (xMax - xMin) * 0.05  
    Me.C1Chart1.ChartArea.AxisX.Min = xMin + xChange 
    Me.C1Chart1.ChartArea.AxisX.Max = xMax - xChange 
    Dim yMin As Double = Me.C1Chart1.ChartArea.AxisY.Min  
    Dim yMax As Double = Me.C1Chart1.ChartArea.AxisY.Max
    Dim yChange As Double = (yMax - yMin) * 0.05  
    Me.C1Chart1.ChartArea.AxisY.Min = yMin + yChange 
    Me.C1Chart1.ChartArea.AxisY.Max = yMax - yChange   
End Sub
'' Controls zooming out     
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click  
    Dim xMin As Double = Me.C1Chart1.ChartArea.AxisX.Min
    Dim xMax As Double = Me.C1Chart1.ChartArea.AxisX.Max
    Dim xChange As Double = (xMax - xMin) * 0.05 
    Me.C1Chart1.ChartArea.AxisX.Min = xMin - xChange  
    Me.C1Chart1.ChartArea.AxisX.Max = xMax + xChange
    Dim yMin As Double = Me.C1Chart1.ChartArea.AxisY.Min
    Dim yMax As Double = Me.C1Chart1.ChartArea.AxisY.Max
    Dim yChange As Double = (yMax - yMin) * 0.05
    Me.C1Chart1.ChartArea.AxisY.Min = yMin - yChange
    Me.C1Chart1.ChartArea.AxisY.Max = yMax + yChange
End Sub

To write code in C#

'// Controls zooming in       
private void button1_Click(object sender, System.EventArgs e)      
{      
    double xMin = this.c1Chart1.ChartArea.AxisX.Min;  
    double xMax = this.c1Chart1.ChartArea.AxisX.Max; 
    double xChange = (xMax - xMin) * 0.05; 
    this.c1Chart1.ChartArea.AxisX.Min = xMin + xChange; 
    this.c1Chart1.ChartArea.AxisX.Max = xMax - xChange; 
    double yMin = this.C1Chart1.ChartArea.AxisY.Min;  
    double yMax = this.C1Chart1.ChartArea.AxisY.Max; 
    double yChange = (yMax - yMin) * 0.05; 
    this.c1Chart1.ChartArea.AxisY.Min = yMin + yChange; 
    this.c1Chart1.ChartArea.AxisY.Max = yMax - yChange;    
}        
'// Controls zooming out       
private void button2_Click(object sender, System.EventArgs e)   
{    
    double xMin = this.c1Chart1.ChartArea.AxisX.Min;   
    double xMax = this.c1Chart1.ChartArea.AxisX.Max; 
    double xChange = (xMax - xMin) * 0.05; 
    this.c1Chart1.ChartArea.AxisX.Min = xMin - xChange; 
    this.c1Chart1.ChartArea.AxisX.Max = xMax + xChange;     
    double yMin = this.c1Chart1.ChartArea.AxisY.Min;  
    double yMax = this.c1Chart1.ChartArea.AxisY.Max; 
    double yChange = (yMax - yMin) * 0.05;  
    this.c1Chart1.ChartArea.AxisY.Min = yMin - yChange; 
    this.c1Chart1.ChartArea.AxisY.Max = yMax + yChange;    
}

See Also

Zooming, Panning, and Scaling with Multiple Y-axes