Articles in this section
Category / Section

Customization of SVG template

2 mins read

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,
     });

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied