How can I start with an existing XML model in mxgraph. I have a default XML graph and i want to import it on mxgraph load (start)
Asked
Active
Viewed 823 times
1 Answers
0
Using the GraphEditor - Template
You can set a default mxGraphModel
by appling it with setGraphXML
.
The following example shows you how to apply a default mxGraphModel.
In the data
-object, declare your default model as xml. Then you can parse the model with parseXml
to xml and then apply it to the graph.
Implementation of setGraphXML in the GraphEditor
var data =
'<mxGraphModel pageWidth="1169" pageHeight="827" background="#ffffff">' +
' <root>' +
' <mxCell id="0" />' +
' <mxCell id="1" parent="0" />' +
' </root>' +
'</mxGraphModel>';
graph.model.beginUpdate();
try {
var xml = mxUtils.parseXml(data).documentElement;
setGraphXml(xml);
}
catch (e) {
console.log(e);
}
finally {
graph.model.endUpdate();
}

Okeano
- 108
- 1
- 8
-
Hello thanks Okeano, I put it in index file and i got this javascript error " this.editorUi is undefined " – achekra Feb 25 '19 at 21:13
-
Hi, I updated the code in my answer(removed the linking to the editorUi and editor). To get this code working in your case, you have to implement the function [setGraphXML](https://github.com/jgraph/mxgraph/blob/e407026f5db3d40d3e39b3396dbed1b03e6f9608/javascript/examples/grapheditor/www/js/Editor.js#L469) into your index-file. – Okeano Feb 25 '19 at 21:45
-
Hello, I got "this graph is not defined" You can find my index file in this link https://tatbikat.ma/index.txt – achekra Feb 26 '19 at 16:41
-
`graph` is the mxGraph-Object. You have to replace this to your mxGraph-Object variable. – Okeano Feb 26 '19 at 16:47
-
I don't have an mxGraph-Object in my index.php can tou take a look to my code in https://tatbikat.ma/index.txt – achekra Feb 26 '19 at 16:49
-
Ok i found the solution of my problem i create a new editorUI Thank you Okeano – achekra Feb 27 '19 at 12:12