Creating SVG-Plots

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

ffiala wrote at 2012-01-08 20:20:

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?

objo wrote at 2012-01-08 22:47:

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.

pver wrote at 2012-02-05 12:47:

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,

objo wrote at 2012-02-08 09:13:

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.

pver wrote at 2012-02-08 16:26:

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.

ffiala wrote at 2012-02-21 07:08:

Thank You all for making my examples work!