Hi Nitin for making zoom i want to use this portion of code:
https://www.grapecity.com/componentone/docs/win/online-flexchart/zoom.html
And I comment all the pan rows that you write for me
#region "FlexChart Events for Zoom and Pan"
private void _fChart_DoubleClick(object sender, EventArgs e)
{
try
{
{
_fChart.BeginUpdate();
_fChart.AxisX.Min = _xInitMin;
_fChart.AxisX.Max = _xInitMax;
_fChart.AxisY.Min = _yInitMin;
_fChart.AxisY.Max = _yInitMax;
_maxZoomX = "";
_minZoomX = "";
_chartZoomIsActive = false;
_fChart.EndUpdate();
}
}
catch (Exception ex)
{
ctrlLogger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
ctrlLogger.Error(ex.Message + "\n" + ex.StackTrace);
if (ex.InnerException != null)
ctrlLogger.Error("Inner exception: " + ex.InnerException.Message);
}
}
private void UpdatedZoomRangeValues(string minX, string maxX, double minAxisY, double maxAxisY)
{
_minZoomX = minX;
_maxZoomX = maxX;
string lbl_MinY = minAxisY.ToString("N2");
string lbl_MaxY = maxAxisY.ToString("N2");
}
private void _fChart_MouseUp(object sender, MouseEventArgs e)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
_IsMouseDown = false;
if (!_lastPoint.IsEmpty)
{
var start = _fChart.PointToData(_startPoint);
var last = _fChart.PointToData(_lastPoint);
float XMin = Math.Min(start.X, last.X);
float XMax = Math.Max(start.X, last.X);
float YMin = Math.Min(start.Y, last.Y);
float YMax = Math.Max(start.Y, last.Y);
_fChart.AxisX.Min = XMin;
_fChart.AxisX.Max = XMax;
_fChart.AxisY.Min = YMin;
_fChart.AxisY.Max = YMax;
_fChart.EndUpdate();
}
_startPoint = _lastPoint = Point.Empty;
}
}
catch (Exception ex)
{
ctrlLogger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
ctrlLogger.Error(ex.Message + "\n" + ex.StackTrace);
if (ex.InnerException != null)
ctrlLogger.Error("Inner exception: " + ex.InnerException.Message);
}
}
private void _fChart_MouseMove(object sender, MouseEventArgs e)
{
try
{
if (_IsMouseDown && e.Button == MouseButtons.Left)
{
var ptCurrent = e.Location;
var left = (int)_fChart.PlotRect.Left;
var right = (int)_fChart.PlotRect.Right;
var top = (int)_fChart.PlotRect.Top;
var bot = (int)_fChart.PlotRect.Bottom;
ptCurrent.X = ptCurrent.X < left ? left : ptCurrent.X > right ? right : ptCurrent.X;
ptCurrent.Y = ptCurrent.Y < top ? top : ptCurrent.Y > bot ? bot : ptCurrent.Y;
_lastPoint = ptCurrent;
_fChart.Refresh();
}
}
catch (Exception ex)
{
ctrlLogger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
ctrlLogger.Error(ex.Message + "\n" + ex.StackTrace);
if (ex.InnerException != null)
ctrlLogger.Error("Inner exception: " + ex.InnerException.Message);
}
}
private void _fChart_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
_IsMouseDown = true;
_startPoint = e.Location;
_lastPoint = Point.Empty;
}
}
catch (Exception ex)
{
ctrlLogger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
ctrlLogger.Error(ex.Message + "\n" + ex.StackTrace);
if (ex.InnerException != null)
ctrlLogger.Error("Inner exception: " + ex.InnerException.Message);
}
}
private void _fChart_Rendered(object sender, RenderEventArgs e)
{
if (!_startPoint.IsEmpty && !_lastPoint.IsEmpty)
{
var p1 = _startPoint;
var p2 = _lastPoint;
e.Engine.SetFill(null);
e.Engine.SetStroke(Brushes.Red);
e.Engine.SetStrokeThickness(1);
e.Engine.SetStrokePattern(new double[] { 3, 3 });
e.Engine.DrawRect(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y), Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y));
}
}
private void PerformPan(System.Drawing.PointF start, System.Drawing.PointF end)
{
double currentXMin = (_fChart.AxisX as C1.Chart.IAxis).GetMin();
double currentXMax = (_fChart.AxisX as C1.Chart.IAxis).GetMax();
double currentYMin = (_fChart.AxisY as C1.Chart.IAxis).GetMin();
double currentYMax = (_fChart.AxisY as C1.Chart.IAxis).GetMax();
var deltaX = (end.X - start.X);
var deltaY = (end.Y - start.Y);
_fChart.BeginUpdate();
if (currentXMin - deltaX >= _xInitMin && currentXMax - deltaX <= _xInitMax)
{
_fChart.AxisX.Min = Math.Max(currentXMin - deltaX, _xInitMin);
_fChart.AxisX.Max = Math.Min(currentXMax - deltaX, _xInitMax);
}
if (currentYMin - deltaY >= _yInitMin && currentYMax - deltaY <= _yInitMax)
{
_fChart.AxisY.Min = Math.Max(currentYMin - deltaY, _yInitMin);
_fChart.AxisY.Max = Math.Min(currentYMax - deltaY, _yInitMax);
}
_fChart.EndUpdate();
}
#endregion