I would like to know how I can get (specifically), just the x-coordinate of a scatterplot that I've plotted using OxyPlot.
//user clicks on graph line data...
//x-coordinate gets assigned to variable
int x = ...
I'm using winforms.
EDIT:
private void plotView_Click(object sender, EventArgs e){
plotView.ActualModel.Series[0].MouseDown += (s, e0) =>
{
if (e0.ChangedButton != OxyMouseButton.Left)
return;
else
pointx = (int)e0.HitTestResult.NearestHitPoint.X;
};
}
WORKING CODE:
s0.MouseDown += (s, e0) =>
{
if (e0.ChangedButton == OxyMouseButton.Left)
{
var item = e0.HitTestResult.Item as ScatterPoint;
if (item != null)
{
pointx = (int)item.X;
}
}
};
You can attach to the mouse down event for your series like so:
var model = new PlotModel { Title = "Test Mouse Events" };
var s1 = new LineSeries();
model.Series.Add(s1);
double x;
s1.MouseDown += (s, e) =>
{
x = e.Position.X;
};
Adapted from their sample code found here: https://github.com/oxyplot/oxyplot/blob/09fc7c50e080f702315a51af57a70d7a47024040/Source/Examples/ExampleLibrary/Examples/MouseEventExamples.cs
and demonstrated here: http://resources.oxyplot.org/examplebrowser/ => scroll down to Mouse Events
EDIT: I found out that the position you get from x is a screen coordinate that you have to convert to find the correct axis point like so:
x = (s as LineSeries).InverseTransform(e0.Position).X;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.