ToSvg

Oystein Bjorke 10 jaar geleden 0
This discussion was imported from CodePlex

nicolasr75 wrote at 2013-05-16 02:59:

Hi all,

I'm trying to export an oxyplot to svg using the PlotModel.ToSvg() method. However, I don't quite understand the parameters.

What does the "isDocument" parameter mean?

What does the "textMeasurer" parameter mean?

An example on how to use the method would be great!

Thanks for any idea.
Nick

nicolasr75 wrote at 2013-05-17 23:46:

I have just found the answer in the ExportDemo in the examples. Simply great !!!

Nick

objo wrote at 2013-06-08 12:00:

isDocument - set to true if you want to produce a .svg file. Set to false if you want to create an <svg> element to use in html5.
textMeasurer - the svg render context needs to measure the size of text. You need to provide a platform specific render context that can do this since the core library does not have access to any methods that can measure text

LazyJames wrote at 2013-07-01 11:20:

Hi,

I am exporting the plot to a HTML5 svg tag. I am not using silverlight or WPF. I need to be able to generate a textMeasurer for this. I have looked through the tests source code and can not find an example of this apart from the silverlight and WPF ones.

If anyone could point me in the correct direction i would be grateful.

objo wrote at 2013-07-02 14:54:

There is also a render context based on Windows Forms, can you reference OxyPlot.WindowsForms in your solution? I think this is the best choice if you are making something for ASP.NET.

You could also create a render context using p/invoke to gdi32 to measure the strings
http://www.pinvoke.net/default.aspx/gdi32/gettextextentpoint.html

It would be great to know better solutions to this...

Roark wrote at 2013-09-19 01:59:

Using the clue from above that I could reference Oxyplot.WindowsForms I got it to work by creating my own GraphicsRenderContext class using the existing code. I changed the scope from "Inner" to "Public" and added the Import OxyPlot.WindowsForms
' -------------------------------------------------------------------------------------------
' <copyright file="GraphicsRenderContext.cs" company="OxyPlot">
'   The MIT License (MIT)
'
'   Copyright (c) 2012 Oystein Bjorke
'
' -------------------------------------------------------------------------------------------

Imports OxyPlot.WindowsForms

Namespace OxyPlot.WindowsForms


    ''' <summary>
    ''' The graphics render context.
    ''' </summary>
    Public Class GraphicsRenderContext
        Inherits RenderContextBase
Then I was able to do this:
Dim rc As New GraphicsRenderContext
Dim bmpOut As System.Drawing.Bitmap = New System.Drawing.Bitmap(800, 600)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmpOut)
rc.SetGraphicsTarget(g)
Dim svg As String = MyPlot.ToSvg(800, 600, False, rc)