Nevron .NET Vision
Framework / Web Forms / Response Types / SVG Response

In This Topic
    SVG Response
    In This Topic
     Overview
    SVG (Scalable Vector Graphics) is a XML based language for describing two-dimensional vector and mixed vector/raster graphics. The component has extensive SVG support for any graphics rendered in 2D mode. The SVG export is supported in both the Windows Forms and Web Forms editions of the control. The following sections will teach you how to configure either the Chart or the Diagram (a component) to render in SVG.
     Configuring A Component To Use SVG Rendering

    In order to send SVG content to the client browser the chart must generate a NImageResponse and the ImageFormat should be set NSvgImageFormat. The following code snippet configures a component to use SVG rendering:

    C#
    Copy Code
    NImageResponse imageResponse = new NImageResponse();
    imageResponse.ImageFormat = new NSvgImageFormat();
    //[theComponent] is a valid instance of either NChartControl or NDrawingView
    [theComponent].ServerSettings.BrowserResponseSettings.DefaultResponse = svgResponse;
    
    Visual Basic
    Copy Code
    Dim imageResponse As New NImageResponse
    imageResponse.ImageFormat = New NSvgImageFormat
    '[theComponent] is a valid instance of either NChartControl or NDrawingView
    [theComponent].ServerSettings.BrowserResponseSettings.DefaultResponse = imageResponse
    
     Streaming SVG Content To The Client Browser

    As with normal static image response this requires having two pages – the first one has an HTML tag that points to the second page that actually generates the SVG content. The first page must refer to the second one in a similar manner:

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

    The second page must be configured to respond with SVG and to stream the SVG content to the client browser:

    C#
    Copy Code
    NImageResponse imageResponse = new NImageResponse();
    imageResponse.ImageFormat = new NSvgImageFormat();
    imageResponse.StreamImageToBrowser = true;
    
    //[theComponent] is a valid instance of either NChartControl or NDrawingView
    [theComponent].ServerSettings.BrowserResponseSettings.DefaultResponse = svgResponse;
    [theComponent].RenderControl(null);
    
    Visual Basic
    Copy Code
    Dim imageResponse As New NImageResponse
    imageResponse.ImageFormat = New NSvgImageFormat
    imageResponse.StreamImageToBrowser = True
    
    '[theComponent] is a valid instance of either NChartControl or NDrawingView
    [theComponent].ServerSettings.BrowserResponseSettings.DefaultResponse = svgResponse
    [theComponent].RenderControl(Nothing)
    
     Automatic SVG Viewer Download

    The SVG content generated by the component requires a client side plugin, which must be installed on the client machine otherwise the user will not be able to view the SVG content. This section shows how to use the Adobe-provided script that automatically downloads and installs the Adobe SVG Viewer if it is not already present on the machine. The script file "svgcheck.js" which is part of the SVG C# and VB.NET examples checks whether the Adobe SVG Viewer is installed and if not prompts the user to download and install it. You’ll need to include this file in your web project. The following page provides detailed instructions on how to achieve this:

    http://www.adobe.com/svg/workflow/autoinstall.html

    Note that at the time of writing of this article the Adobe script missed the isSVGControlInstalled() function in the .js variant so it's recommended to use the JScript script supplied with the control examples. In general you need place the following script in the page:

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

    Then you need to place the following code in the page, before the the SVG content:

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