Enable scrolling in x-axis for chart control

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 07:38:55

问题


I can't seem to enable a scroll bar on x-axis. I'm using the code below to generate the chart.

List<int> xVal = new List<int>();  
List<int> yVal = new List<int>();  
for (int i = 0; i <= maxQueuetime ; i++)  
{  
    xVal.Add(i);  
    yVal.Add(graph2Yaxis[i]);  
}  
chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;  
chart1.Series[0]["PointWidth"] = "1";  
chart1.Series[0].Points.DataBindXY(xVal, yVal);


回答1:


This will let the user drag over a portion of the chart he want to see and then a scrollbar will show up:

ChartArea CA = chart1.ChartAreas[0];
CA.CursorX.IsUserSelectionEnabled = true;

To make the scrollbar show up by code use at least this line:

CA.AxisX.ScaleView.Zoom(firstDataPoint, lastDataPointInView);

Depending on your data you may want to set the ScaleView.SizeType

CA.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;

I suggest adding a little help to tell the user how to zoom in..

To prevent zooming you can change the default:

CA.AxisX.ScaleView.Zoomable = false;


来源:https://stackoverflow.com/questions/33310126/enable-scrolling-in-x-axis-for-chart-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!