【发布时间】:2014-06-13 11:38:34
【问题描述】:
我正在绘制一个图表,其中填充了从不同程序获得的数据。我想做两个按钮来放大和缩小。我看到我可以使用 AxisX.ScaleView 中的不同功能,我正在使用这些功能。我快到了,但是在绘制图表的那一刻我有一个问题:如果您看到图像1,这是执行不同程序并第一次绘制后的图表。当我进行放大和缩小时,最后一个条形图(图 2 中的第 22 周)被切成两半并且不会恢复到原来的大小。
有谁知道如何操纵 X 轴的开始和结束位置以进行缩放?有谁知道如何获得图表区域开始和结束的初始值?我放置了我的函数代码来缩放图表:
private void setSize(int zoom)
{
int blockSize = (Convert.ToInt32(tbZoom.Text) + zoom) / 100;
// set view range to [0,max]
chartReport.ChartAreas[0].AxisX.Minimum = 0;
chartReport.ChartAreas[0].AxisX.Maximum = chartReport.Series[0].Points.Count;
// enable autoscroll
chartReport.ChartAreas[0].CursorX.AutoScroll = true;
chartReport.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
// let's zoom to [0,blockSize] (e.g. [0,100])
chartReport.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chartReport.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
int actualHeight = chartReport.Height;
int actualWidth = chartReport.Width;
int position = 0;
int size = blockSize;
chartReport.ChartAreas[0].AxisX.ScaleView.Zoom(position, size);
// disable zoom-reset button (only scrollbar's arrows are available)
chartReport.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to blockSize (e.g. 100)
chartReport.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = blockSize;
tbZoom.Text = (blockSize * 100).ToString();
}
【问题讨论】: