private void ChartMouseMove(object sender, MouseEventArgs e) { if (!IsEnabled || !series.Visible) { SetCrosshairVisibility(Visibility.Collapsed); return; } // Clip crosshair lines within a diagram bounds. ClipCrosshairLines(); // Get the current cursor position and transform it to the diagram coordinates. Point position = e.GetPosition(chart); DiagramCoordinates diagramCoordinates = diagram.PointToDiagram(position); if (!diagramCoordinates.IsEmpty) { // Get a value of a series point that is nearest to the current cursor position. double seriesValue = GetSeriesValue(series, diagramCoordinates.DateTimeArgument); if (!double.IsNaN(seriesValue)) { // Specify the text for X and Y crosshair labels. valueX.Text = (diagramCoordinates.DateTimeArgument). ToString("D", CultureInfo.CurrentCulture); valueY.Text = Math.Round(seriesValue, 2). ToString(CultureInfo.CurrentCulture); // Show the crosshair cursor elements. SetCrosshairVisibility(Visibility.Visible); // Convert chart coordinates to screen coordinates to // place crosshair labels along the scale. ControlCoordinates controlCoordinates = diagram.DiagramToPoint(diagramCoordinates. DateTimeArgument, seriesValue); PlaceValuesOnAxis(position.X, controlCoordinates.Point.Y); // Draw the crosshair cursor. Canvas.SetLeft(verticalLine, position.X); Canvas.SetTop(horizontalLine, controlCoordinates.Point.Y); } } else { // Hide the crosshair cursor elements. SetCrosshairVisibility(Visibility.Collapsed); } }
private void UpdateCrosshairPosition() { ClipCrosshairLines(); currentXPosition = GetXPosition(); double seriesValue = GetSeriesValue(series, currentXPosition); ControlCoordinates controlCoordinates = diagram.DiagramToPoint(currentXPosition, seriesValue); SetNumbersToValuePads(seriesValue.ToString("F2")); PlaceValuesOnAxis(controlCoordinates.Point.X, controlCoordinates.Point.Y); SetCrosshairVisibility(Visibility.Visible); Canvas.SetLeft(verticalLine, controlCoordinates.Point.X); Canvas.SetTop(horizontalLine, controlCoordinates.Point.Y); }
protected override ControlCoordinates GetTopLeftCoordinates() { return(diagram.DiagramToPoint( (double)axisX.ActualRange.ActualMinValue, (double)axisY.ActualRange.ActualMaxValue)); }