I use the C # built-in chart control ( System.Windows.Forms.DataVisualization.Charting.Chart ) with its built-in ability to let the user select a range. What I would like to do is read which range the user has selected. Of course, there must be some easy way to do this, but I could not find it.
The cursor is turned on like this:
var ca = chart1.ChartAreas["ChartArea1"].CursorX;
ca.CursorX.IsUserEnabled = true;
ca.CursorX.IsUserSelectionEnabled = true;
I know that I can zoom in on the chart when the user selects a range by turning it on ca.AxisX.ScaleView.Zoomable, but I don’t want the image to change: instead, I use the chart as a way to display information and let the user select a range of X values, for which I then perform some additional processing.
I tried connecting to chart1.SelectionRangeChanged, and it really works with every range change - I just can't get the selection range from CursorEventArg, which I am returning. It has fields " NewSelectionStart" and " NewSelectionEnd", but it is disappointing NaN. I tried to look at the various properties of the diagram and axes, but I did not find anything that sounds promising.
Further research reveals the ChartArea.CursorX.SelectionStart property , which sounds exactly what I need ... except that it is NaN too. I do not know if this is normal, or am I finding some kind of error?
So, how can I determine which range is selected by the user?
source
share