Creating SVG-Plots

Jan 8, 2012 at 7:20 PM
Edited Feb 21, 2012 at 6:05 AM

I wanted to use OxyPlot to generate SVG plots. My first step was to create the examples. The method of the PlotModel ToSvg() is used. But whenever I use examples which add data points or specially scaled axes, the plot fails, saying the reference to these objects is null. But the objects are passed by the example code correctly.

The PieSeries example works

The axis examples with individually parametrized axes does not scale the axis. Code:

var model = new PlotModel("AbsoluteMinimum=-17, AbsoluteMaximum=63", "Zooming and panning is limited to these values.");
model.Axes.Add(new LinearAxis(AxisPosition.Bottom) { Minimum = 0, Maximum = 50, AbsoluteMinimum = -17, AbsoluteMaximum = 63 });  
new LinearAxis(AxisPosition.Left) { Minimum = 0, Maximum = 50, AbsoluteMinimum = -17, AbsoluteMaximum = 63 });  
string Svg = model.ToSvg(800, 400);
// output to webpage 

Other examples are showing errors saying that objects do not exist but the values are given by the example code.

All examples:

I am including OxyPlot and ExampleLibrary to my project (but not OxyPlot.Silverlight, OxyPlot.Metro, OxyPlot.OpenXml, OxyPlot.Pdf.  OxyPlot.WindowsForms, OxyPlot.Wpf,  OxyPlot.Xps).

Does someone have a hint for me?

Jan 8, 2012 at 9:47 PM

thanks for reporting the error - there must be a bug somewhere.

I will look into it soon. Should add a test that exports all example models from the example library to the various output formats.

Your dll reference is ok, only OxyPlot.dll is required when you export to SVG.

Feb 5, 2012 at 11:47 AM

I found the solution for both of the problems you have ffiala. If you first call Update() on the plotmodel you created (just before the ToSvg() call) , both the scaling and rendering with datapoints works as expected:

string Svg = plotModel1.ToSvg(800, 400);

objo, I'll upload a patch that handles this in the ToSvg() method

Kind regards,

Feb 8, 2012 at 8:13 AM

Thanks for the solution, Peter! Is this solving issue 9874? I applied the patch. Sorry I don't have time to test this properly myself right now.

Feb 8, 2012 at 3:26 PM

You're welcome!

This indeed fixes issue 9874. I was able to simulate the exceptions ffiala had before the change. And with the change, the SVGs were exported correctly.

Feb 21, 2012 at 6:08 AM

Thank You all for making my examples work!