0

I am developing windows based application using charts. The chart is a line chart having an x-axis as a System.DateTime type. I am adding real time data to the chart for every 1 sec and I have to display the 10 minutes frame all the time(like 0-10 min, 10-20 min..). For that I set minimum and maximum values of the chart. I did not set the isXValueIndexed property to true. User has a provision to select the datapoint with a mouse click. I need to mark the user selected data point. I tried the following code, but it is not working. Please guide me.

 private void chart1_CursorPositionChanged(object sender, CursorEventArgs e)
    {           
        DataPoint pt = chart1.Series[0].Points[(int)Math.Max(e.ChartArea.CursorX.Position - 1, 0)];

        pt.MarkerStyle = MarkerStyle.Square;
        pt.MarkerColor = Color.Brown;
        pt.MarkerSize = 10;
        pt.MarkerBorderWidth = 5;                

    }

I am getting the e.ChartArea.CursorX.Position value as a double (for example 42502.00002) and getting a System.ArgumentOutOfRangeException.

Nuri YILMAZ
  • 4,291
  • 5
  • 37
  • 43
sowjanya attaluri
  • 903
  • 2
  • 9
  • 27
  • At which line in your code are you getting the `System.ArgumentOutOfRangeException`? I assume it's at the point of: `DataPoint pt = chart1.Series[0].Points[(int)Math.Max(e.ChartArea.CursorX.Position - 1, 0)];`? – Draken May 12 '16 at 08:22
  • @Draken: yes, exactly. – sowjanya attaluri May 12 '16 at 08:25
  • And I'm guessing you don't have 42502 points on your graph? I think you should be using the method `chart1.Series[0].PixelPositionToValue(e.ChartArea.CursorX.Position)`. This will get you the value of the graph at that point, but what you then need to do is check your series values for the one that matches that value. Have a look at [this post](http://stackoverflow.com/questions/9647666/finding-the-value-of-the-points-in-a-chart) for more info – Draken May 12 '16 at 08:38
  • [Here's another suggestion on how to do it](http://stackoverflow.com/questions/9691000/get-mouse-click-event-from-microsoft-chart-control-click-on-data-marker) – Draken May 12 '16 at 08:42

0 Answers0