Skip to content

SP5: Create "Show Value on Hover" demo #3026

@JurasskPark

Description

@JurasskPark

ScottPlot Version: 5.0.10-beta

Operating System: Windows

Application Type: WinForms

Question:
In the demo version there is an example called "ShowValueOnHover2".

private void formsPlot1_MouseMove(object sender, MouseEventArgs e)
    {
      (double x, double y) mouseCoordinates = this.formsPlot1.GetMouseCoordinates();
      (double x, double y, int index) = this.MyScatterPlot.GetPointNearest(mouseCoordinates.x, mouseCoordinates.y, this.formsPlot1.Plot.XAxis.Dims.PxPerUnit / this.formsPlot1.Plot.YAxis.Dims.PxPerUnit);
      this.HighlightedPoint.X = x;
      this.HighlightedPoint.Y = y;
      this.HighlightedPoint.IsVisible = true;
      if (this.LastHighlightedIndex != index)
      {
        this.LastHighlightedIndex = index;
        this.formsPlot1.Refresh(false, false);
      }
      this.label1.Text = string.Format("Closest point to ({0:N0}, {1:N0}) ", (object) e.X, (object) e.Y) + string.Format("is index {0} ({1:N2}, {2:N2})", (object) index, (object) x, (object) y);
    }

Could you suggest an example for Net Core how to implement this.

public string Title => "Mouse Tracker";

    public string Description => "Demonstrates how to interact with the mouse " +
        "and convert between screen units (pixels) and axis units (coordinates)";

    readonly ScottPlot.Plottables.Crosshair CH;

    public MouseTracker()
    {
        InitializeComponent();

        CH = formsPlot1.Plot.Add.Crosshair(0, 0);

        formsPlot1.MouseMove += (s, e) =>
        {
            // demonstrate pixel-to-coordinates
            Pixel px = new(e.X, e.Y);
            Coordinates coordinates = formsPlot1.GetCoordinates(px);

            // demonstrate coordinates-to-pixel
            Pixel px2 = formsPlot1.Plot.GetPixel(coordinates);

            // place the crosshair where the mouse is
            CH.Position = coordinates;
            formsPlot1.Refresh();

            // display where the mouse is in the titlebar
            Text = $"{px2} {coordinates}";
        };
    }

How can I implement the same functionality on version 5?

trend

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions