Below is my code…
when i click on a button it generates the diagram perfectly but when i click on that button again it says …Error: Invalid div id; div already has a Diagram associated with it…could you please tell me what am i doing wrong…i tried using Diagram.div = null;
but its not working at all.
Thanks
var $1 = go.GraphObject.make;
myDiagram = $1(go.Diagram, “myDiagramDiv”,
{
initialContentAlignment: go.Spot.Center,
“undoManager.isEnabled”: true,
allowDragOut: false
});
myDiagram.nodeTemplate =
$1(go.Node, “Auto”,
$1(go.Shape, “Ellipse”, { strokeWidth: 5 },
new go.Binding(“fill”, “color”)),
$1(go.TextBlock, { margin: 8 },
new go.Binding(“text”, “key”))
);
var linkDataArray = [];
var linkerData = [];
for (var i = 0, j = 0; i < Session.get('gojsname1').length, j < Session.get('gojsname2').length; i++, j++) {
linkDataArray.push({ key: Session.get('gojsname1')[i], color: "orange" }, { key: Session.get('gojsname2')[j], color: "orange" });
linkerData.push({ from: Session.get('gojsname1')[i], to: Session.get('gojsname2')[j] });
}
for (var iter = 0; iter < linkDataArray.length; iter++) {
for (var innerIter = 0; innerIter < linkDataArray.length; innerIter++) {
if (iter != innerIter) {
if (linkDataArray[iter].key == linkDataArray[innerIter].key) {
linkDataArray.splice(innerIter, 1);
}
}
}
}
myDiagram.model = new go.GraphLinksModel(
linkDataArray, linkerData
);
Thanks for solution walter… But will u please mention where exactly we need to clear the div… In my case iam getting empty div after reloading…since iam clearing the div just before creating my diagram.modal
Are you trying to replace the diagram entirely, or just the model? If you just want to use a new model, you don’t need to set myDiagram.div = null, you can just set Diagram.model to the new model.
Hi …iam trying to create diagram…with same name and inserting in same div… But each time I am calling same java script function by passing diff values for nodes and links… So,on first call iam able to view diagram…on second call iam facing an error "Error: Invalid div id; div already has a Diagram associated with it. "… Then I tried with diagram.div =null … But This is clearing the diagram before displaying…