| ||
Introducing SharpPlot Your First Chart Recent Updates Sample Charts Tutorials General Tutorials Chart Tutorials SharpPlot Class Properties Methods Structures Enumerations Style examples Active Charts VectorMath Class DBUtil Class Get SharpPlot Download SharpPlot Buying SharpPlot SharpPlot Support Upgrading from GraPL Release notes |
Reference > Glossaries > Rendering Options Rendering OptionsSharpPlot 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:
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 MetafileSharpPlot simply returns a Metafile object containing your chart. Metafile mychart = sp.RenderMetafile(); There are no other options here. Rendering the finished chart as VMLThis 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 SVGThis 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 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 <img src="Frequency.asp" height=432 width=576 border=0 > SummaryWith 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 ... |