Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Vertical ValueOverlay on CategoryDateTimeXAxis
posted

This is currently my code:

 

private void AddEventTimeOverlay()

{

ValueOverlay overlay = new ValueOverlay();

CategoryDateTimeXAxis xaxis = (CategoryDateTimeXAxis)MChart.Axes.First((axis) => axis.Name.Equals("SharedXAxis"));

overlay.Axis = xaxis;

double scaledx = xaxis.GetScaledValue(eventTime.Ticks, MChart.WindowRect, GetViewportRect(xaxis));

overlay.Name = "EventTimeOverlay";

overlay.Value = scaledx;

overlay.Thickness = 2;

overlay.Brush = new SolidColorBrush(Colors.Magenta);

 

//overlay.Axis = (NumericYAxis)MChart.Axes.First((axis) => axis.Name.Equals("SharedYAxis"));

//overlay.Value = 0.21;

//overlay.Thickness = 2;

//overlay.Brush = new SolidColorBrush(Colors.Purple);

 

MChart.Series.Add(overlay);

}

 

private Rect GetViewportRect(Axis axis)

{

double top = 0;

double bottom = axis.ActualHeight;

double left = 0;

double right = axis.ActualWidth;

 

double width = right - left;

double height = bottom - top;

 

if (width > 0.0 && height > 0.0)

{

return new Rect(left, top, width, height);

}

return Rect.Empty;

}

 

 

For some reason, no overlay is showing up for me. I'm not sure if the problem is the DateTime to Double value conversion, or if there's something else going on. When I try to display a horizontal valueOverlay, it shows up fine (I tested using the code that is commented out).

 

Suggestions?