diagram.layout is not a function

receiving the following console TypeError:
diagram.layout is not a function

Code snippet:

        drop: function (args) {
            var diagram = $("#diagram").ejDiagram("instance");
            if (!args.source.cssClass) {
                console.log("NEW DROP");
                if (diagram.getObjectType(args.target) == "node") {
                    if (args.element) {
                        var connector = diagram.findNode(args.element.inEdges[0]);
                    }
                    if (connector) {
                        diagram.updateConnector(connector.name, { sourceNode: args.target.name, targetNode: args.element.name });
                    }
                    else {
                        diagram.add({ name: "connector" + ej.datavisualization.Diagram.Util.randomId(), segments: [{ type: "orthogonal" }], sourceNode: args.target.name, targetNode: args.element.name });
                    }
                }
            }
            diagram.layout();
        },

1 Reply 1 reply marked as answer

AR Aravind Ravi Syncfusion Team November 17, 2020 12:15 PM UTC

Hi Dsoftware, 

We suspect that the issue occurs due to you have get the diagram element from wrong id, so that diagram instance does not get and layout of undefined issue occurs. Get the diagram instance from the diagram id. After get the diagram instance you can able to access the diagram properties and public methods. Please refer to the below code snippet 

<div> 
        @Html.EJ().Diagram("Label", ViewData["diagramModel"] as Syncfusion.JavaScript.DataVisualization.Models.DiagramProperties) 
    </div> 
  var diagram = $("#Label").ejDiagram("instance"); 

So please get diagram element from proper diagram id. 

Regards 
Aravind Ravi 


Marked as answer
Loader.
Up arrow icon