Serialization is the process of saving and loading for state persistence of the diagram.
The diagram is serialized as string while saving. The client-side method,
saveDiagram helps to serialize the diagram as a string. The following code illustrates how to save the diagram.
var diagramElement = document.getElementById('element'); var diagram = diagramElement.ej2_instances; var saveData; //returns serialized string of the Diagram saveData = diagram.saveDiagram();
This string can be converted to JSON data and stored for future use. The following snippet illustrates how to save the serialized string into local storage.
//Saves the string in to local storage localStorage.setItem('fileName', saveData); saveData = localStorage.getItem('fileName');
Diagram can also be saved as raster or vector image files. For more information about saving the diagram as images, refer to
Print and Export.
Diagram is loaded from the serialized string data by client-side method,
The following code illustrates how to load the diagram from serialized string data.
var diagramElement = document.getElementById('element'); var diagram = diagramElement.ej2_instances; //Loads the Diagram from saved json data diagram.loadDiagram(saveData);
Note: Before loading a new diagram, existing diagram is cleared.