我正在绘制一张图表,我用从不同程序获得的数据填充图表。我想让两个按钮放大和缩小。我看到我可以使用AxisX.ScaleView中的不同功能,并且我正在使用这些功能。我几乎在那里,但是在绘制图表的时候我有一个问题:如果您看到图像1,这是执行不同过程并首次绘制图表后的图表。当我进行放大和缩小时,最后一个小节(图像2中的第22周)被减半,并没有达到其原始大小。绘制我在其中操纵放大和缩小的图表
有没有人有任何想法如何操纵轴X的开始和结束位置,以便进行缩放?有谁知道如何获取图表区域开始和结束的initian值?我把我的函数的代码,以使图表变焦:
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();
}
就是这样。我认为这将是一件小事,会有所作为。接受答案! –