Articles in this section

How to use uploader for a changing image in shape and diagram background image in Vue Diagram?

In Syncfusion® Vue Diagram , you can easily customize both the diagram background and node shapes. To change the diagram’s background, set the image path using the background source property in the pageSettings. This allows you to apply custom colors or images. The node shapes can be dynamically updated at runtime using the shape property. This feature enables you to assign custom images to nodes via an image uploader.
To customize, select a node and click the Change Node Image button, which opens the uploader dialog. You can then select an image to place inside the node. Similarly, click the Change Background button to update the diagram’s background image.

Refer to the below code snippet

reader.onloadend = () => {
         const imageSource = reader.result;

         // If changing the background
         if (this.imageFor === "Background") {
           // Update background source
           diagramInstance.pageSettings.background.source = imageSource;
           diagramInstance.pageSettings.background.color = "transparent"; 
           diagramInstance.dataBind(); // Data binding for background
         }
         // If changing the node image
         else if (this.imageFor === "Shape" && diagramInstance.selectedItems.nodes.length > 0) {
           let selectedNode = diagramInstance.selectedItems.nodes[0];
           selectedNode.shape = { type: "Image", source: imageSource }; // Set the node image source

           // Refresh to reflect changes
           diagramInstance.refresh(); 
           diagramInstance.dataBind(); // Ensure the diagram rebinds the new image
         }
       }; 

Sample : Click here for sample

Conclusion

I hope you enjoyed learning how to use uploader for a changing image in shape and diagram background image in Vue Diagram

You can refer to our Vue 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 Vue 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 forums, Direct-Trac, 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)
Access denied
Access denied