简体   繁体   中英

Oxyplot - edit the left-click label in a LineSeries

I'm plotting a few different LineSeries in Oxyplot (in C#, using Windows Forms), which all have wildly different ranges. To make every series still visible, I'm scaling all their values to the range from 0 to 1. Of course the problem here is, that the actual values of the series can't be displayed anymore, so I wondered if it's possible to change the left-click event that displays the X and Y value of a DataPoint to fix this. If possible, I'd like it so that when the user clicks on a datapoint, the displayed Y-value would be scaled back to the original, while the graph remains scaled down.

For example, I have a Na+ value ranging from 130 to 150, which I then scale to 0 and 1. But when the user clicks on a Datapoint, I want it to display Y = 140 and not 0.5. Since every LineSeries has a different scaling factor, this would also mean that I'd have to edit the label for each series seperately.

So yeah, is something like that possible in the current version? Thanks in advance!

Edit: I figured it out, see my answer below!

I'm not sure if I'm supposed to answer my own question, but I ended up figuring it out. So anyway, it turns out I can't access any of the properties needed, so I just made my own class for the Datapoints and included a property for the scaled value. It turns out that the Tracker is capable of displaying other properties of the Datapoints, but the standard Datapoints only has X and Y. Then I modified the TrackerFormatString to show the scaled value instead of the actual one.

        public class MeasurePoint : IDataPointProvider
    {
        public MeasurePoint(double x, double y, double scale)
        {
            X = x; Y = y; Scale = scale;
        }

        public double X { get; set; }
        public double Y { get; set; }
        public double Scale { get; set; }
        public DataPoint GetDataPoint()
        {
            return new DataPoint(X, Y);
        }
    }

That is the class I created and this is how I ended up handling the points.

            var points = new MeasurePoint[Y.Count - 1];
        for (int i = 0; i < Y.Count; i++)
        {
            points[i] = new MeasurePoint(DateTimeAxis.ToDouble(X[i]), Y[i], Y[i]*scale);
        }
        Series.ItemsSource = points;
        Series.TrackerFormatString = "{0}\n{2}\n{Scale}";

scale here is the factor that I divide the values with before plotting and the TrackerFormatString is {0} the Series name and {2} is the X value.

Works pretty great!

You can't directly change the displayed data, however you can listen to the mousedown event within the oxyplot like this:

var model= new PlotModel();
model.MouseDown += Model_MouseDown;

private void Model_MouseDown(object sender, OxyMouseDownEventArgs e)
{
    var controller = sender as PlotController;
    var position = e.HitTestResult;
}

With the values of position you can calculate back to the actual value and display it somewhere else.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM