Reference > Glossaries > Rendering Options

Rendering Options

SharpPlot can generate the finished chart in any of five common vector formats and any image format supported by the .net Bitmap. The vector formats are:

  • EMF (Enhanced Metafile). This is ideal for saving as a temporary format, and pasting into Word or PowerPoint.
  • VML (Vector Markup Language) is the current best choice if you know your users will have IE5 or above (with the VML option enabled) on a Microsoft platform. It is based on a W3C proposal (May 1998) but is unlikely to progress to a ratified open standard. VML charts print at high quality from IE5 and above.
  • SVG (Scalable Vector Graphic) is a ratified W3C standard and is generally a superset of VML. It is currently supported by Adobe who provide a free plugin which works on most browsers (but not currently on FireFox) and operating systems. Check the Adobe website for the latest information. The printing quality should eventually match what you get from VML.
  • PDF (Portable Document Format) is a good format if you want to email a completed chart, or post several charts as a single document on your website. It might be a convenient way of packaging a large collection of graphs, with an appropriate navigation tree created by SharpPlot as bookmarks. It is the only format which works well with multiple pages.
  • EPS (Encapsulated PostScript). This is very suitable for including single charts in published documents prepared with high-end DTP software for printing on any PostScript device.

In general, any vector format will be smaller (in byte count) than the corresponding raster image by a factor of between 5 and 10. VML currently has the major benefit that the entire page is ‘inline’ with no callbacks to the server to retrieve pictures. It is likely that in the near future it will be possible to include SVG graphics as an XML namespace in the same way, at which point SVG may become the preferred option. For the moment it is only possible to refer to SVG graphics with an <embed> tag which generates a second call to the server to build the chart. There are several more detailed comparisons of the three formats on www.grapl.com with examples of charts for easy comparison of file size and quality.

Rendering to a Metafile

SharpPlot simply returns a Metafile object containing your chart.

Metafile mychart = sp.RenderMetafile();

There are no other options here.

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"/>
<style>
 v\:* {behavior=url(#default#VML)}
</style>

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.

Rendering the finished chart as SVG

This is a very similar process to rendering in VML, as SVG is also a text XML format. Currently the SVG cannot reliably be placed inline, so the entire result is returned as xml text, and should be marked as content type “image/svg+xml”:

string mysvg = sp.RenderSvg(SvgMode.FixedSize)

The calling page will require an appropriate <embed> tag, such as:

<embed src="mychart.aspx" height=300 width=640 type="image/svg+xml" >

SVG charts scale very well, so you could make the chart larger simply by increasing the height and width in proportion. Charts may be drawn at fixed size in the browser, or you can use various ‘modes’ to change how they scale:

string mysvg = sp.RenderSvg(SvgMode.FixedAspect) // Scale to fit (keep shape)
string mysvg = sp.RenderSvg(SvgMode.Stretchable) // Scale to width and ht

Rendering to PostScript (PDF or EPS)

PostScript is another text format, so you would normally simply assign the chart to an appropriate variable:

 string mypdf = sp.RenderPdf();
 string myeps = sp.RenderEps();

If you want to write the PDF content directly into a webpage, you should give it the correct content type “application/pdf”, and link to it with an appropriate <embed> tag such as:

<embed src="makepdf.aspx" height=300 width=640 type="application/pdf" >

The ‘PageMode’ parameter of RenderPDF should be set to FullScreen here, which causes the Acrobat Reader to occupy the entire frame set up by the <embed> tag with no toolbars or scrollbars. If you render a multipage PDF here, set the flag to ShowOutlines and allow enough extra space for the outline pane and Acrobat Reader toolbars. You will probably need to experiment to get the height and width to look correct.

Rendering the finished chart as an image (PNG, BMP, GIF, JPEG or TIF)

In this case the completed chart is returned as a Bitmap object, which may then be used to generate the required image format to save on disk, or return to the browser via http:

Bitmap bmp = sp.RenderBitmap(72);

The RenderBitmap command takes the DPI to create the image at. To have the bounding box of the chart match the required height and width of the image, use 72 for the DPI setting. If you increase this number (say to 96) remember to adjust the parameters in the image tag to match. If you are creating charts to be printed, you could try RenderImage(300) which will generate a much larger picture.

Here is an image tag suitable for a chart created with SharpPlot(432,324) and rendered with sp.RenderImage(96) to scale it up a little:

<img src="Frequency.asp" height=432 width=576 border=0 >

Summary

With SharpPlot you can render the completed chart in a variety of vector formats or images with only minimal change to the sourcecode. You might like to check for the browser capabilities in your script (e.g. to detect IE5 or above) and switch formats as required depending on the target platform.

See also ...

SharpPlot Members


Send comments on this topic
© Dyalog Ltd 2013