SharpPlot Reference > SharpPlot Methods > RenderVml Method

SharpPlot.RenderVml Method

Return completed chart rendered as Vector Markup (VML).

VML is not supported by Microsoft and should not be used, unless for backwards compatibility reasons.

public string RenderVml();

Return Value

The result of this call is a string representation of a partial HTML document. This may be written to file as text, or returned via HTTP as a section in a normal webpage. You may have several VML sections in a single page. They are automatically named with the current chart name if this is set to a non-default value.

If your page has any VML content, it must begin with the standard VML header to define the behavior of the <v:xxx> tags to the browser.


string myvml = sp.RenderVml();


Sizing the rendered graphic

The default is to express all text sizes and positions in pts (72 pts = 1 inch) and to use pts to give the size of the entire block of VML. If you prefer to use pixels, you can pass the required dpi conversion (passing 96 here will have no visible effect on most video adaptors at default resolution). This allows you to fix the size of the graphic more reliably on websites which use pixels for design reasons. It also allows you to make thumbnails of the charts with no extra processing.

Working with VML

Please note that VML is a Microsoft-specific format and is only supported in Internet Explorer 5.5 and above. However it runs ‘native’ in the browser and can be used to put an entire page inline, rather than required callbacks to the server to obtain charts as SVG or raster images.

To make IE understand the VML tags, you MUST include the appropriate behavior tag in the header, so the sample code shown below is typical of what you need to create a functional webpage:

   // Render to HTML file as VML
    StreamWriter sw = new StreamWriter("Simple.htm",false,System.Text.Encoding.ASCII);
    string chart = sp.RenderVml(false);
    sw.Write(sp.VmlHeader);  // Add the header detail
    sw.Write("<title>SharpPlot - Simple chart</title>");

This will create a complete page with your chart shown correctly within it.

Rendering the finished chart as VML

This is the simplest option for internet use, as the chart can be included directly into the html page under construction:

string mychart = sp.RenderVml()

The call to RenderVml completes the current chart and returns the entire chart definition as a simple XML string bounded by <div> .... </div> tags. For this to be shown by the browser, you must ensure that your page has the correct VML header section to declare the XML namespace:

<xml:namespace prefix="v"/>
 v\:* {behavior=url(#default#VML)}

You can include these yourself, or have SharpPlot define them for you:

string vmlHeader = sp.VmlHeader

This must go right at the top of the page, before even the <head> section. You can then construct the remainder of the page as normal, including as many VML sections as you need, as part of the HTML output stream.

See also ...

SharpPlot Members | SharpPlot.VmlHeader Property | SharpPlot.SaveVml Method | SharpPlot.SetChartName Method

Send comments on this topic
© Dyalog Ltd 2021