Hello Geoff,
Currently there isn't a Horizontal Line Cursor with the same properties and functionalities as in Vertical Cursor. Though LineSeriesCursor's style can be changed to HairCrossTracking which draws both horizontal and vertical lines. However, the horizontal line cannot be dragged.
There are still many ways to draw a movable horizontal line across the chart. A line collection, another PointLineSeries or even an X-axis could be used. However, the best option most likely is ConstantLine, which draws a line at given Y-value. The line can also be dragged up or down. The following draws a red line at Y-value 5:
Code: Select all
ConstantLine cl = new ConstantLine(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
cl.LineStyle.Width = 2;
cl.LineStyle.Color = Color.Red;
cl.Value = 5;
_chart.ViewXY.ConstantLines.Add(cl);
The only downside of this is that ConstantLine doesn't have series tracking options (SnapToPoints, solving intersection points etc.). If you need to for example solve intersection points between the ConstantLine and some line series, you need solve them in code. This can be done with help of ConstantLine's ValueChanged -event (triggers every time when Y-value has been changed) and LineIntersection method in MathRoutines class. The following adds a marker at every intersection point:
Code: Select all
cl.ValueChanged += Cl_ValueChanged;
private void Cl_ValueChanged(object sender, ValueChangedEventArgs e)
{
_chart.BeginUpdate();
PointLineSeries pls = _chart.ViewXY.PointLineSeries[0];
pls.SeriesEventMarkers.Clear();
for (int i = 0; i < pls.PointCount - 1; i++)
{
PointFloat inter;
if (MathRoutines.LineIntersection(new PointFloat((float)_chart.ViewXY.XAxes[0].Minimum, (float)e.NewValue), new PointFloat((float)_chart.ViewXY.XAxes[0].Maximum, (float)e.NewValue),
new PointFloat((float)pls.Points[i].X, (float)pls.Points[i].Y), new PointFloat((float)pls.Points[i + 1].X, (float)pls.Points[i + 1].Y), out inter))
{
SeriesEventMarker marker = new SeriesEventMarker();
marker.AllowUserInteraction = false;
marker.HorizontalPosition = SeriesEventMarkerHorizontalPosition.AtXValue;
marker.VerticalPosition = SeriesEventMarkerVerticalPosition.AtYValue;
marker.XValue = inter.X;
marker.YValue = inter.Y;
marker.Label.Text = "X: " + inter.X.ToString("0.0");
pls.SeriesEventMarkers.Add(marker);
}
}
_chart.EndUpdate();
}
Hope this helps.
Best regards,
Lasse