)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

Customization of SVG template

Platform: jQuery |
Control: ejDiagram |
Published Date: November 11, 2016 |
Last Revised Date: May 30, 2019

Customization of SVG template

We can customize the SVG template and render it as a native node. If we set an attributes for an SVG and set a same property in the native node, then the property in the node can be overridden by the inline style or SVG element specified in the template. Please refer to the code example in which we have customized the SVG template.

Code example:

[JS]   
 
 <!--set an svg gradient-->
    <svg height="150" width="400">
        <defs>
            <lineargradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
                <stop offset="0%" style="stop-color:green;stop-opacity:1" />
                <stop offset="100%" style="stop-color:white;stop-opacity:1" />
            </lineargradient>
        </defs>
        <defs>
            <lineargradient id="grad2" x1="0%" y1="0%" x2="100%" y2="100%">
                <stop offset="0%" style="stop-color:white;stop-opacity:1" />
                <stop offset="100%" style="stop-color:red;stop-opacity:1" />
            </lineargradient>
        </defs>
    </svg>
    <script id="svgTemplate" type="text/x-jsrender">
        <g>
            <path d="M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z" fill="url(#grad2)" stroke="green" stroke-width="2" stroke-opacity=0.2></path>
            <path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0Z" fill="url(#grad1)" stroke="green" stroke-width="2" stroke-opacity=0.2></path>
        </g>
    </script>
 
    var nodes = [
                             {
                                   name: "NativeNode", width: 50, height: 60, offsetX: 300, offsetY: 100,
                                   type: ej.datavisualization.Diagram.Shapes.Native, templateId: "svgTemplate",
                             },
                          ];
 
     $("#diagram").ejDiagram({
               nodes: nodes,
       });
 

 

The scale property of node allows to stretch the svg content as you desired (either to maintain proportion or to stretch). By default, the scale property of node is set as “meet”. The following code illustrates how to scale or stretch the content of the node. Please refer to the code example below.

Code example:

[JS]
 
   var nodes = [
                            {
                                 name: "NativeNode", width: 50, height: 60, offsetX: 300, offsetY: 100,
                                 type: ej.datavisualization.Diagram.Shapes.Native, templateId: "svgTemplate",
                                 scale: "stretch"
                            },
                     ];
 
   $("#diagram").ejDiagram({
            nodes: nodes,
     });

 

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon