JSONObject n3 = new JSONObject();
n3.put("id", new JSONNumber(3));
n3.put("text", new JSONString("Node 3"));
JSONArray nodes = new JSONArray();
nodes.set(0, n1);
nodes.set(1, n2);
nodes.set(2, n3);
JSONObject l1 = new JSONObject();
l1.put("from", new JSONNumber(1));
l1.put("to", new JSONNumber(2));
JSONObject l2 = new JSONObject();
l2.put("from", new JSONNumber(1));
l2.put("to", new JSONNumber(3));
JSONObject l3 = new JSONObject();
l3.put("from", new JSONNumber(2));
l3.put("to", new JSONNumber(3));
JSONArray links = new JSONArray();
links.set(0, l1);
links.set(1, l2);
links.set(2, l3);
JSONObject p1 = new JSONObject();
p1.put("from", new JSONNumber(1));
p1.put("to", new JSONNumber(2));
p1.put("duration", new JSONNumber(5));
JSONObject p2 = new JSONObject();
p2.put("from", new JSONNumber(1));
p2.put("to", new JSONNumber(3));
p2.put("duration", new JSONNumber(3));
JSONObject p3 = new JSONObject();
p3.put("from", new JSONNumber(2));
p3.put("to", new JSONNumber(3));
p3.put("duration", new JSONNumber(1));
JSONArray packages = new JSONArray();
packages.set(0, p1);
packages.set(1, p2);
packages.set(2, p3);
// Create options
Network.Options options = Network.Options.create();
options.setWidth("300px");
options.setHeight("300px");
options.setStabilize(false);
options.setBackgroundColor("#E4F3F8");
options.setBorderWidth(0);
options.setLinksLength(100);
options.setLinksWidth(2);
// create the visualization, with data and options
network = new Network(nodes.getJavaScriptObject(),
links.getJavaScriptObject(),
packages.getJavaScriptObject(),
options);
network.addSelectHandler(createSelectHandler(network));
RootPanel.get("mynetwork").add(network);