Dundas Chart for ASP.NET
Using SVG Rendering
See Also Send comments on this topic.
Using Dundas Chart > Rendering > Using SVG Rendering



Glossary Item Box

Overview

Enterprise Edition Only Feature.

The Scalable Vector Graphics (SVG) file format is a vector graphics file format, and web development language based on XML. SVG enables web developers to create dynamically generated, high-quality graphics with precise structural and visual control. Using Dundas Chart for ASP.NET, you can create SVG charts based on data-driven, interactive, or personalized graphics. 

Advantages vs. Disadvantages

Some of the advantages of SVG include:

 

Some of the disadvantages of SVG include:

 

How to Render as SVG

Setting a chart to render in SVG format requires that you simply set the ImageType property. This can be done from within the Property Browser or programmatically.

Example

This example demonstrates how to set the image format type to SVG.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
   ...
   
' Set the ImageType to render in SVG format.
Chart1.ImageType = ChartImageType.SVG


                    
C# Copy Code
using Dundas.Charting.WebControl;
   ...

// Set the ImageType to render in SVG format.
Chart1.ImageType = ChartImageType.SVG;


                    

 

Chart Scaling

When SVG Document is rendered in a browser there is possibility that picture could be resized as the browser is resized.

To activate auto resizing the height and width should be set as a % of the browser using the width and height attributes.

There is also an additional attribute, PreserveAspectRatio, that will maintain the proportions of Height and Width preventing image distortion as the image is dynamically resized.

 

Note
The limitation for a SVG resizable picture is that tooltips functionalities are disabled.

 

Example

This example demonstrates how to add scaling attributes.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
   ...
       
' Enable resizing of SVG Document.
Chart1.Attributes("Height") = "70%"
Chart1.Attributes("Width") = "70%"
' Resizable picture could keep aspect ratio or not.
Chart1.Attributes.Add("preserveAspectRatio", "true")


                    
C# Copy Code
using Dundas.Charting.WebControl;
   ...

// Enable resizing of SVG Document.
Chart1.Attributes["Height"] = "70%";
Chart1.Attributes["Width"] = "70%";

// Resizable picture could keep aspect ratio or not.
Chart1.Attributes.Add("preserveAspectRatio", "true");


                    

 

In cases where the chart image must be saved, you may use the Save method of the Chart object. Either of the Save methods shown below will allow you to save the XML formatted SVG chart to a file for later use.

    public void Save (string imageFileName, ChartImageFormat format );
    public void Save ( Stream svgStream, ChartImageFormat format );

Example

This example demonstrates how to save a chart as an SVG file.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
   ...
   
' Explicit Call to Save method to save the Chart in SVG format.
Chart1.Save("SVGChartImage.svg", ChartImageFormat.SVG)


                    
C# Copy Code
using Dundas.Charting.WebControl;
   ...

// Explicit Call to Save method to save the Chart in SVG format.
Chart1.Save("SVGChartImage.svg", ChartImageFormat.SVG);


                    

 

Custom Painting When Using SVG

Custom drawing is supported using the BackPaint, and PostPaint event of Chart Graphics object. SVG custom drawing uses the same set of methods as would normally be used for painting in other non-vector formats. 

Any custom drawn element may also have Href links, tooltips, or both. This is example using a Paint event to draw two circles which are selectable, and also have tooltips.

Example

This example demonstrates how to work with custom painting.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
   ...
   
If (sender = ChartArea) Then
    ' Initialize a hot region. All elements drawn before EndHotRegion
    ' called will be selectable and have the same tooltip.
    ChartGraphics.StartHotRegion("www.dundas.com", "Dundas Software")
    ' Get the drawing rectangle for the first ellipse.
    Dim ellipseRect As RectangleF = e.ChartGraphics.GetAbsoluteRectangle(New RectangleF(10, 10, 20, 20))
    ' Draw the first ellipse.
    e.ChartGraphics.DrawEllipse(New Pen(Color.Red), ellipseRect)
    ' Get the next ellipse rectangle.
    ellipseRect = e.ChartGraphics.GetAbsoluteRectangle(New RectangleF(5, 5, 10, 10))
    ' Draw the next ellipse.
    e.ChartGraphics.DrawEllipse(New Pen(Color.Red), ellipseRect)
    ' End the hot region.
    e.ChartGraphics.EndHotRegion
End If


                    
C# Copy Code
using Dundas.Charting.WebControl;
   ...

if(sender is ChartArea)
{
  // Initialize a hot region. All elements drawn before EndHotRegion
  // called will be selectable and have the same tooltip.
  ChartGraphics.StartHotRegion("www.dundas.com", "Dundas Software");
  // Get the drawing rectangle for the first ellipse.
  RectangleF ellipseRect = e.ChartGraphics.GetAbsoluteRectangle(new RectangleF(10, 10, 20, 20 ));
  // Draw the first ellipse.
  e.ChartGraphics.DrawEllipse(new Pen(Color.Red),ellipseRect);
  // Get the next ellipse rectangle.
  ellipseRect = e.ChartGraphics.GetAbsoluteRectangle( new RectangleF( 5, 5, 10, 10 ));
  // Draw the next ellipse.
  e.ChartGraphics.DrawEllipse( new Pen(Color.Red),ellipseRect);
  // End the hot region.
  e.ChartGraphics.EndHotRegion();
}


                    

 

Drawing with a transparent color can be used to create selectable regions, or regions with a specific tooltip that are not visible when the chart is rendered. Similar to the sample above, the code must begin with StartHotRegion method, and end with EndHotRegion methods. All chart drawing is done in the usual way, but instead of using another color, the transparent color gets used.

 

Binary Streaming and SVG

Similar to rendering charts in a typical image format, you can render a SVG chart using either the Binary Streaming method, or as an Image Tag. When rendering your chart using the binary streaming method, an <embed> tag is used, however, if you render your chart as an image, then an html <img> tag is used instead.

For more information on rendering charts, see the topic on Rendering Methods.

Example

This example demonstrates how to use binary stream rendering as SVG.

HTML Copy Code
<embed src="WebForm3.aspx" pluginspage=http://www.adobe.com/svg/viewer/install/ width="500" height="300" TYPE="image/svg+xml">


                    

 

Using the Automatic SVG Viewer Download

In order for your end-users to see SVG file, they must have the Adobe SVG viewer installed on their machine. This viewer plugin is available for free from Adobe, and can be downloaded from their website located at: http://www.adobe.com/svg/viewer/install/main.html.

Example

This example demonstrates how to use the Adobe-provided script, which may be embedded in an HTML page to automatically download, and install the Adobe SVG Viewer, that is of course, if the viewer is not already installed on the end-user's machine. The script files "svgcheck.js", and "svgcheck.vbs" are necessary to make it all work. Place these files on your website, and include them in your HTML document as shown below.

JavaScript Copy Code
<script language="JavaScript" src="svgcheck.js"></script>
<script language="VBScript" src="svgcheck.vbs"></script>


                    

 

The following code must be added to your application in order to call the JavaScript code above, which will in turn test for the availability of the SVG viewer.

Example

JavaScript Copy Code
<script language="JavaScript">
<!--
 checkAndGetSVGViewer();
// -->
</script>


                    

See Also

Copyright © 2001 - 2009 Dundas Data Visualization, Inc. and others.