Tracker Format for Custom data points

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

cz9qvh wrote at 2014-06-11 23:27:

I have a quick question about custom tracker formats. I have created a ScatterSeries in my view model like so:
Series = new ScatterSeries());
Series.TrackerFormatString = "match: {Match}";
and I'd like this match data to come from my data point, so I have a custom datapoint class like this:
public class MyDataPoint : ScatterPoint {
  public string Match {get;set;}
  public MyDataPoint(double x, double y, string match):base(x,y) { Match = match; }
}
and then I add these points to the scatter series like this:
Series.Points.Add(new MyDataPoint(5,10,"Message about this"));
But when I click on these points, I get a Null reference exception from PlotView and the program crashes.

I thought I used the wrong TrackerFormatString so tried this one but it had the same result
Series.TrackerFormatString = "Match {DataPoint.Match}";
How've I gone wrong here?

mhedqvist1 wrote at 2014-06-13 12:59:

I have the same problem using ScatterPoint as base with a similar implementation.

In previous projects I used IDataPoint, but that seems to be removed now..

cz9qvh wrote at 2014-06-16 16:23:

Yes, and it seems weird to me that the HitResult that goes into TrackerEventArgs for the TrackerChanged event has a DataPoint when the Series type is ScatterSeries. Shouldn't this be a ScatterPoint? I guess with the IDataPoint interface gone there isn't a good way to do polymorphism between DataPoint's and ScatterPoint's. I suppose this means that before the when the HitResult is constructed the X and Y from the ScatterPoint are copied to the a newly constructed DataPoint? Not sure, maybe I'll look at the code today.

mhedqvist wrote at 2014-07-29 11:15:

Look some more on this after my vacation and solved my problem after finding the CustomTrackerDemo..

In my XAML I added:
<oxy:PlotView ... >
                <oxy:PlotView.DefaultTrackerTemplate>
                    <ControlTemplate>
                        <oxy:TrackerControl Position="{Binding Position}" LineExtents="{Binding LineExtents}">
                            <oxy:TrackerControl.Content>
                                <TextBlock Text="{Binding}" Margin="8"/>
                            </oxy:TrackerControl.Content>
                        </oxy:TrackerControl>
                    </ControlTemplate>
                </oxy:PlotView.DefaultTrackerTemplate>
</oxy:PlotView>
In my viewmodel I have a ScatterSeries
 var scatterSeries = new ScatterSeries
      {
        ...
        TrackerFormatString = "{ToolTip}"
      };
      
which I add a custom data point to
 public class ScatterPointWithToolTip : ScatterPoint
  {
    public string ToolTip { get; private set; }

    public ScatterPointWithToolTip(double x, double y, ...., object tooltip) 
      : base(x, y...)
    {
      ToolTip = (string) tooltip;
    }
  }