2014-06-13 2 views
0

다른 절차에서 얻은 데이터로 채울 차트를 그립니다. 확대 및 축소 버튼 두 개를 만들고 싶습니다. 나는 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(); 
} 

This is image 1:

And this is image 2:

답변

2

첫 번째 라인은 축 잘못의 최대 설정입니다 : 22-chartReport.ChartAreas[0].AxisX.Maximum = chartReport.Series[0].Points.Count; 세트를, 정말 23 일 때 (첫 번째 이미지를 기반으로). 데이터는 항상 다음과 같이됩니다

, 단순히 1을 추가 불행하게도

chartReport.ChartAreas[0].AxisX.Maximum = chartReport.Series[0].Points.Count + 1; 

를 차트가 실제로 그려 때까지 당신에게 실제 값을 제공하지 않습니다 자동 최소/최대 값을 사용. 차트에 DataPoints이 거의 없다면 chartReport.Refresh(); 또는 비슷한 것을 호출 한 다음 축에서 값을 가져올 수 있으므로 문제가되지 않습니다. 그러나 많은 포인트가 있다면 Refresh()은 오랜 시간이 걸리므로 바람직하지 않습니다. 차트를 광범위하게 사용하면서 자동 최소/최대 값을 사용하는 대신 전체 범위를 제어하도록 축 범위를 직접 설정했습니다.

+0

그게 전부입니다. 차이를 만들만한 작은 것이 될 것이라고 생각했습니다. 답변을 수락했습니다! –