Add nodes to the diagram at specific positions

Hi, i want to add a node to the diagram on the right of the rightmost node, so i find the position of the rightmost node is x and y. Now i want to add a new node with the code like this:

var nodeData= NodeArray;
nodeData.loc = x + 200 + “” + y;
myDiagram.model.addNodeData(nodeData);


//the nodeArray is like
//NodeArray[0]={category: “pic”, text: “aggregator”,img: “aggregator.png”,key : “aggregator”};


this doesn’t work and the node added to the diagram at the center. I don’t know whether i need a startTransaction and a commitTransaction or not?


Thanks for the help :)

The State Chart sample demonstrates how to do that in the addNodeAndLink function.

Perhaps your problem is that you are setting the “loc” property on the Array, not on a new JavaScript object that needs to be added to the model’s nodeDataArray and will be represented by the new Node.

the error i met is "
property set error: Error: Part.location value is not an instance of Point: 200 0 "


so i try setting like this


nodeData.loc = new go.Point(200,200);


and it works