如何用go.js单纯的做出一个矩形

看了官网形状那个代码,如何实现只有一个矩形

This creates a red rectangular shape of a particular size:

    $(go.Shape, { fill: "red", width: 100, height: 50 })

But you can only add Parts to a Diagram, not any GraphObject.

If you want that one rectangle to be in the model, use a template like:

  myDiagram.nodeTemplateMap.add("Rectangle",
    $(go.Part,
      $(go.Shape, { fill: "red", width: 100, height: 50 })
    ));

and model data such as:

  { category: "Rectangle" }

You could of course use data binding in order to customize the shape.

If you want that one rectangle not to be in the model, just add it to the Diagram with a position or location:

  myDiagram.add(
    $(go.Part,
      { location: new go.Point(140, -60) },
      $(go.Shape, { fill: "red", width: 100, height: 50 })
    ));

When the part is not in the model, data binding does not work.