Skip to main content

add()

adds a new item to the diagram

add(new_item: IDataItem | IDataItem[]): Id | Id[];

Parameters:

new_item: object | array - the object of a new item or an array of item objects

Returns:

Either a string with the item's id or an array of string values with ids of items.

Example

diagram.data.add({ id: "3.2", text: "New Item", parent: "3" });

Related sample: Diagram. Data. Add/delete item

Details

There are two ways to link shapes, you can add a shape with a parent ID defined:

diagram.data.add({ id: "3.2", text: "New Item", type: "card", parent: "3" });

or you can add a shape and a connector line objects:

diagram.data.add({ type: "card", id: "3.2", text: "New Item" });
diagram.data.add({ type: "line", from: "3", to: "3.2" });

Adding an item