2
votes

I'm working on a chart that contains 4 series: The x-axis is date and the y-axis scales from -10 to 10. Each data point (regardless of series) falls on a different day, although the series do represent different measurements.

I have created the chart that fills from a SQL-query and gotten a vertical line to move horizontally along with the cursor. What I'd like to do next (but have gotten rather stumped) is compare the position of the vertical line with the data points (regardless of which series) and highlight the point visually (and extract the x/y values for dig-down chart information).

I have some ideas about how to step through the different series, but I'm not getting how to create a date-time window (of ~half a day) around my scrolling-vertical-line--how to interface that vertical line with the data-points in the time series. Perhaps I'm just not thinking about the problem correctly?

Here's my code for the mouse move, but I haven't gotten anything working for the portion in question:

private void calCheckChart_MouseMove(object sender, MouseEventArgs e) {
    // Set style of cursor over chart, including dotted vertical line

    calCheckChart.ChartAreas[0].CursorX.IsUserEnabled = true;
    calCheckChart.ChartAreas[0].CursorX.Interval = 0;
    calCheckChart.ChartAreas[0].CursorX.LineColor = Color.Black;
    calCheckChart.ChartAreas[0].CursorX.LineWidth = 1;
    calCheckChart.ChartAreas[0].CursorX.LineDashStyle = ChartDashStyle.Dot;

    // Move the vertical line with cursor
    Point cursorDate = new Point(e.X);
    calCheckChart.ChartAreas[0].CursorX.SetCursorPixelPosition(cursorDate, true);

    // ...
}

Thanks for your time looking this over. Any insights are greatly appreciated.

1

1 Answers

1
votes

I figured it out! From where I left off in the preceding code, I first determined what my CursorX position values were outputting, which was OADate. Once I knew this, I constructed a foreach statement (as provided below) for each one of my series: first initializng the visual-attributes of the data points (pt), then checking if a data point fell within a 0.9 day interval centered on the cursor (CursorX-0.4 < pt < CursorX+0.5) and if so, change the marker type/size. I then used the same foreach (and enclosed if statement) for each of my 4 series on the chart, changing only the index of the series.

So this hops between series to whichever datapoint falls within the selected range, and also selects multiple datapoints in multiple series if they should fall on the same date.

          // Scan through series and find the nearest datapoint within a given time interval
            foreach (DataPoint pt in calCheckChart.Series[0].Points)
            {
                // Initialize point attributes.
                pt.MarkerStyle = MarkerStyle.None;
                // Check if the cursor's x-value is the near a point in series, and if so highlight it
                if (pt.XValue > calCheckChart.ChartAreas[0].CursorX.Position - 0.4 && pt.XValue < calCheckChart.ChartAreas[0].CursorX.Position + 0.5)
                {
                    pt.MarkerStyle = MarkerStyle.Circle;
                    pt.MarkerSize = 8;
                    // toolStripStatusLabel1.Text = pt.YValues[0].ToString();
                }
            }

 // ...