Search code examples
c#chartslivecharts

Livecharts and mouse position


I would like to know if there is a way to get the position X and Y of the cursor (mouse) on the chart ?

For the moment I am stuck with the onData which provide me only the position of an existing point.

I would like to get the position of the mouse even if it doesn't concern a point.

For exemple, on the MS Datavisualization chart, i can get these values with :

Chart myChart;
ChartArea ca = myChart.ChartAreas[0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY; 
double X = ax.PixelPositionToValue(e.X);
double Y = ay.PixelPositionToValue(e.Y);

with e, the MouseEventArgs.

I have tried this, not work :

Chart_TCC.MouseMove += Chart_TCC_MouseMove;
private void Chart_TCC_MouseMove(object sender, MouseEventArgs e)
{
    string mouseX = e.X.ToString();
    string mouseY = e.Y.ToString();

    MessageBox.Show("X = " + mouseX + " - Y = " + mouseY);
}

Do you know if there is this function in the LiveCharts library ?

Thank you for your help.


Solution

  • Here you can find example of getting chart coordinates: https://github.com/Live-Charts/Live-Charts/tree/master/Examples/Wpf/CartesianChart/SectionsMouseMove https://lvcharts.net/App/examples/v1/Wpf/Visual%20Elements