Articles in this section
Category / Section

How to load SVG file into JavaScript Diagram?

1 min read
This article explains how to load an SVG file into a JavaScript diagram. You can load the SVG content, and the diagram is achieved on the application side. The addEventListener event in FileReader is used to get the SVG content. So, each group element in the SVG file can be added as an individual native node.

A simple sample has been created for loading an SVG file into the diagram. Please refer to the code example and sample as follows.


TS

reader.addEventListener("load", function (event) {
    var shape;
      var shapeContent = event.target.result;
      shape = { id: 'newflow' + id.toString(), shape: { type: 'Native', content: shapeContent }, offsetX: 150, offsetY: 150, height: 75, width: 75 };
      diagram.add(shape);
  });
  id++
  reader.readAsText(file);
 
  uploadObj.clearAll();
 
}

 

Refer to the working sample for additional details and implementation: Sample 


Conclusion

We hope you enjoyed learning about how to load an SVG file into a diagram.

You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.  You can also explore our JavaScript Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsBoldDesk Support, or feedback portal. We are always happy to assist you!

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