2017-08-11 13 views
-1

C#、WinFormでマウスホイールをズームしているときにスクロールすると、グラフの画像が大きく拡大し、ポイントが表示されません。 y軸、それを修正する方法はありますか?
これはコードですが、xminymaxを変更する必要があると思いますが、私は方法を理解できません。ここでマウスホイールズームC#スクロール時にグラフのサイズを変更しないでください

は私のコードです:

private void chart_MouseWheel(object sender, MouseEventArgs e) 
{ 
    try 
    { 
     if (e.Delta < 0) 
     { 
      chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(); 
      chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset(); 
     } 

     if (e.Delta > 0) 
     { 
      double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum; 
      double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum; 
      double yMin = chart1.ChartAreas[0].AxisY.ScaleView.ViewMinimum; 
      double yMax = chart1.ChartAreas[0].AxisY.ScaleView.ViewMaximum; 

      double posXStart = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMin)/2; 
      double posXFinish = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMax)/2; 
      double posYStart = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMin)/2; 
      double posYFinish = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMax)/2; 

      chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish); 
      chart1.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish); 
     } 
    } 
    catch { } 
} 

答えて

0

私はこの1つの賛成で私の古い答えを削除しました:

変更をposXStartposXFinishposYStart、そしてposYFinishの定義に:

double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/2.25; 
double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/2.25; 
double posYStart = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin)/2.25; 
double posYFinish = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin)/2.25; 

実際に何が起こっているか考えてみると、あなたの使用のためのより良いズームを得るためにそれらの最後の数字を覚えておいてください。それは2または2.5または4か何でもかまいません。

関連する問題