在c#中移动缩放图表

问题描述 投票:0回答:1

我使用以下代码来创建图表

chart1.Series[0].ChartType = SeriesChartType.Line;
chart1.DataSource = dict;
chart1.Series[0].XValueMember = "Key";
chart1.Series[0].YValueMembers = "Value";
chart1.Series[0].IsVisibleInLegend = false;

chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0.00";
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "0.00";

chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;

chart1.Refresh();

和以下代码用滚动放大图表

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) - (xMax - xMin) / 4;
double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin) / 4;
double posYStart = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin) / 4;
double posYFinish = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin) / 4;

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

我试图能够在我按住左键的同时用鼠标移动缩放图表。

c# charts mschart
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.