0

I am using the AreaSeries in Oxyplot to graph a range between two points and would like the Tracker to display both of them when hovered. I achieved making the Tracker display custom properties with other series by creating a custom class for the DataPoints and changing the TrackerFormat accordingly. Here is an example:

    public class CommentPoint : IScatterPointProvider
    {
        public CommentPoint(double x, double y, string text)
        {
            X = x; Y = y; Text = text;
        }
        public double X, Y;
        public string Text { get; set; }
        public ScatterPoint GetScatterPoint()
        {
            return new ScatterPoint(X, Y);
        }
    }

And the TrackerFormat:

Series.TrackerFormatString = "{2}\n{Text}";

However, this only works when adding an array of the new points as the ItemSource of the series. With Line/ScatterSeries it's easy, since they require just a list of points. But an AreaSeries requres 2 points to be graphed.

I tried adding a 2d array of these custom points as the ItemSource:

    public class AreaPoint : IDataPointProvider
    {
        public AreaPoint(double x, double y, double y2)
        {
            X = x; Y1 = y; Y2 = y2;
        }

        public double X { get; set; }
        public double Y1 { get; set; }
        public double Y2 { get; set; }
        public DataPoint GetDataPoint()
        {
            return new DataPoint(X, Y1);
        }
    }

So basically:

AreaPoint[,] points = new AreaPoint[2,amount.Count]
AreaPoint[0,i] = new AreaPoint(x,y,y2);
....
Series.ItemSource = points;

That doesn't work and I recieved an error "Is not a one-dimentional array".

Next I tried adding the points directly via the GetDataPoint method:

Series.Points.Add(new AreaPoint(x,y,y2).GetDataPoint());
Series.Points2.Add(new AreaPoint(x2,y2,y3).GetDataPoint());
Series.TrackerFormatString = "{2}\n{4}\n{Y2}";

This works in that the AreaSeries is being plotted correctly, but the Tracker won't display my custom properties.

So I suppose my question is, how can I add a custom ItemSource to an AreaSeries?

JohnH
  • 45
  • 8

1 Answers1

0

You can just add X2, Y2 fields to your custom point class and set DataField properties in your AreaSeries.

public class AreaPoint : IDataPointProvider
{
    public AreaPoint(double x, double y, double x2, double y2, string customValue)
    {
        X = x;
        Y = y;
        X2 = x2;
        Y2 = y2;
        CustomValue = customValue;
    }

    public double X { get; set; }
    public double Y { get; set; }
    public double X2 { get; set; }
    public double Y2 { get; set; }
    public string CustomValue { get; set; }
}

...
series = new AreaSeries();
series.DataFieldX = "X";
series.DataFieldY = "Y";
series.DataFieldX2 = "X2";
series.DataFieldY2 = "Y2";
series.TrackerFormatString = "{0}\n{1}: {2}\n{3}: {4}" + 
    "\nMy custom value: {CustomValue}"
Souple
  • 1