Overlay Curve with Bar Series?

Sep 30, 2013 at 11:51 PM
Edited Sep 30, 2013 at 11:52 PM
Hi,
I just started looking around in case the chart I am using now does not support my needs amply. Wondering, will the OxyPlot chart support a bar series with a smooth curve overlaid. I am looking to show where the bars fall with respect to a fitted curve (i.e. overlaid curve).

Thanks!
Alan
Oct 1, 2013 at 4:58 PM
You can use a PolylineAnnotation for this, simply give it the list of fitted points and use Smooth = true.

There's an example in the AnnotationExamples called PolylineAnnotations.
Oct 2, 2013 at 12:19 AM
Gimly, Fantastic and thanks! I will give that a try. Best, Alan
Oct 3, 2013 at 7:37 AM
Gimly,
Do you happen to have any ideas? I am stuck on this error

Error 2 Argument 1: cannot convert from 'OxyPlot.Wpf.PolylineAnnotation' to 'OxyPlot.Annotations.Annotation' D:\Development\Samples\OxyPlotSample\OxyPlotSample\MainWindow.xaml.cs 83 33 OxyPlotSample

which is caused by this line
        tmp.Annotations.Add(new PolylineAnnotation { Points = new IDataPoint[] { new DataPoint(0, 15), new DataPoint(3, 23), new DataPoint(9, 30), new DataPoint(20, 12), new DataPoint(30, 10) }, Smooth = true, Text = "Smooth Polyline" });
I tried casting the "new PolylineAnnotation" to "OxyPlot.Annotations.Annotation" with no luck.

I am not quite sure what to try next. This is a .Net/WPF application.

Thanks,
Alan
Oct 3, 2013 at 8:24 AM
Are you adding the PolylineAnnotation in your code-behind? If so try to refer to your model in the plot:

if plotter is the x:Name of your plot in XAML

in the code behind you need to set something like:
plotter.Model.Annotations.Add(myPoly); 
instead of simply
plotter.Annotations.Add(myPoly);
Good luck
Oct 3, 2013 at 3:57 PM
Edited Oct 3, 2013 at 7:07 PM
Hi Everytimer,
Thanks for the reply! Yes, PolylineAnnotation is in the code-behind accessing the PlotModel. The XAML refers to the PlotModel through this binding with other properties (i.e. code behind accessing PlotModel) working as expected.
            <oxy:Plot x:Name="MyPlot" Model="{Binding Model1}">
            </oxy:Plot>
I tried your idea of accessing the model directing by naming the plot:
this.MyPlot.Model.Annotations.Add(new PolylineAnnotation { Points = new IDataPoint[] { new DataPoint(0, 15), new DataPoint(3, 23), new DataPoint(9, 30), new DataPoint(20, 12), new DataPoint(30, 10) }, Smooth = true, Text = "Smooth Polyline" });
Unfortunately, I am getting the same compiler error:
Argument 1: cannot convert from 'OxyPlot.Wpf.PolylineAnnotation' to 'OxyPlot.Annotations.Annotation' 
The compiler is seeing Annotations" with the "Add" method, but it looks like it is unable to accept the PolylineAnnotation object in the Add method. The Add method is expecting something it can convert to OxyPlot.Annotations.Annotation. I got this line using PolylineAnnotation from the general examples since I could not find it in the WPF samples.

Thanks!
Alan
Oct 3, 2013 at 9:18 PM
Ok, I think you have
using OxyPlot.Wpf;
on top, if so try to add the "normal" PolylineAnnotation:
var myPoly = new OxyPlot.Annotations.PolylineAnnotation() { /* stuff */};
MyPlot.Add(myPoly);
Good luck!
Oct 4, 2013 at 7:00 AM
Hi Everytimer,

Beautiful, it compiles - thank you!

Best,
Alan