0

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!

JohnH
  • 45
  • 8
  • I guess displaying the actual values within the plot will be rather difficult, but maybe you can listen to the mouseevent, get the plot-values and from those you can calculate back to the actual values and display them in a textbox or label? – Roland Deschain Nov 20 '18 at 14:22
  • Ah, so get the plot-values from the event, then hide the tracker and display it in a label insted? I'll try that as plan B, if I can find out where the mouse-event is. Thanks! – JohnH Nov 20 '18 at 14:37
  • Put this as answer, let me know if this works for you. – Roland Deschain Nov 20 '18 at 14:42

2 Answers2

1

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!

JohnH
  • 45
  • 8
0

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.

Roland Deschain
  • 2,211
  • 19
  • 50
  • Ah yes, that works, thank you! So now I have the X/Y values and which LineSeries they belong to all in the position object, I'm just trying to figure out how to access those properties. Would I need to add any get methods to the Oxyplot.HitTestResult class? – JohnH Nov 20 '18 at 15:03
  • Hmm sorry, I can't test any code atm. Can't you just assign a new variable to the value of the position x and y values? – Roland Deschain Nov 20 '18 at 16:00
  • I can see the X and Y values when debugging, but it won't let me access the properties in code. I tried something like var x = position.X, if that's what you meant. – JohnH Nov 21 '18 at 07:06
  • That's weird, according to the [sourcefiles](https://github.com/ylatuya/oxyplot/blob/master/Source/OxyPlot/PlotModel/HitTestResult.cs) the `HitTestResults` properties should be public. Same goes for [ `ScreenPoint.X` and `ScreenPoint.Y` ](https://github.com/ylatuya/oxyplot/blob/master/Source/OxyPlot/Foundation/ScreenPoint.cs). Have you tried accessing the Index? In principle that is all you would need. (Sorry I also just did a short debug-test on this and won't be able to look at code until tomorrow. – Roland Deschain Nov 21 '18 at 10:27
  • Yes, I thought so too, but I can't seem to access HitTestResult.Item.X. The index works, thank you, although I'd still need the position.Element.Title property to know which LineSeries the click belongs to and that one seems to the inaccessible as well. Would I have to edit the sourcefile somehow and make these properties public? I tried to find how and where, but I can't seem to get it right. – JohnH Nov 21 '18 at 12:24