0
Under review

Linking data series and annotations

concentriq fa 9 anys updated by anonymous fa 9 anys 5
Hello..  I am trying to place textual information above particular points in the series, and have them be linked, meaning that if I scroll around the plot, the text is always in the same position relative to a particular point in the series. like so:

my lets say length of my int[] data is 15 and it contains values {22, 44, 55, 87, 33, 21, 23, 44, 33, 42, 54, 56, 66, 77, 99}

I need to place letter "H" over position 3, "Z" over position 8, and "T" over position 12. All annotations are near the top of the plot area. My code works fine displaying regular LineSeries but I cant figure out how to add the annotations.  Any help is appreciated


public void SetWaveformData(int[] data)
{
PlotModel plotModel = new PlotModel();
List<DataPoint> dataSeries = new List<DataPoint>();
int i = 0;
foreach (int yValue in data)
{
dataSeries.Add(new DataPoint { X = i++, Y = yValue });
}
LineSeries ser = new LineSeries();
ser.Points.AddRange(dataSeries);
plotModel.Series.Add(ser);
}
Under review
I see two possible solutions:
1. use TextAnnotations for the H,Z and T labels
2. use the labelling feature for the LineSeries. Create a new point type that also includes a property that returns "H","Z","T" or null. Bind the points to the ItemsSource on the LineSeries, and set the format string for the labels to use the property just mentioned. I am not sure if this works right now, but it should be easy to fix!
Hello. thank you very much for you reply. I am sorry if this is redundant, but I am missing something I think:
How does one "set the format string for the labels to use the property just mentioned."

I created a class called AnnotatedDataPoint from IDataPointProvider, implemented DataPoint GetDataPoint() and added a property called Label with getter and setter. default value is null, just like you said.

Then I created a List<AnnotatedDataPoint> and populated it with data and assigned proper labels to some datapoints.

It displays waveform if I do this
List<AnnotatedDataPoint> dataSeries = new List<AnnotatedDataPoint>(); 

<...populate dataSeries...> 

LineSeries lineSeries = new LineSeries();

lineSeries.ItemsSource = dataSeries;
which tells me that I implemented my AnnotatedDataPoint correctly, but from here how do I actually assign the "Label" property to format string? Again, help is much appreciated.
+1
See the `LineSeries.LabelFormatString`. I think you can set it to "{Label}", where "Label" is the name of the property in your AnnotatedDataPoint that contains the labels. This is using the extended string formatting syntax (that I hope works, otherwise it is an easy fix!)

ps. It would be great to have this added as an example in the example library!
there could also be an `ILabelProvider` interface to improve performance (avoid the reflection)