TrueChart for WinForms (C1Chart2D)
ズーム効果の生成
グラフのインタラクティブ操作 > 回転、拡大/縮小、移動、ズーム > ズーム効果の生成

グラフでズーム効果を生み出すには、軸を調整するだけです。たとえば、2つのボタンコントロール(〈ズームイン〉ボタンと〈ズームアウト〉ボタン)をアプリケーションに追加し、Button_Click イベントに次のようなコードを設定します。

Visual Basic コードの書き方

Visual Basic
コードのコピー
' ズームインを制御      
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
' ズームアウトを制御     
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

C# コードの書き方

C#
コードのコピー
// ズームインを制御       
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;    
}        
// ズームアウトを制御       
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;    
}
関連トピック