我试图在html按钮单击上绘制圆形图(希望在不能正常工作的kendo图工具栏上使用它),addShape方法似乎运行正常,没有任何错误,但是该图未显示在页面上。
但是,绘制圆形时,初始剑道图负载没有问题。



$(document).ready(createDiagram);

function createDiagram() {
  $("#diagram").kendoDiagram({
    shapes: [{
        type: 'circle',
        fill: {
          color: 'blue'
        }
      },
      {
        type: 'rectangle'
      }
    ],
    shapeDefaults: {
      editable: {
        tools: ["createShape", "delete", "rotateClockwise", "rotateAnticlockwise"]
      }
    },
    connectionDefaults: {
      stroke: {
        color: "#979797",
        width: 1
      },
      type: "polyline",
      startCap: "FilledCircle",
      endCap: "ArrowEnd"
    },
    editable: {
      tools: ["createShape", "delete", "rotateClockwise", "rotateAnticlockwise"]
    }
  });
  $("#diagram").getKendoDiagram().layout();
}

function drawCircle() {
  var diagram = $("#diagram").getKendoDiagram();

  /*diagram.addShape(new kendo.dataviz.diagram.Point(100, 220), {
    background: "red"
  });*/
  diagram.addShape(new kendo.dataviz.diagram.Circle({
    radius: 600,
    stroke: {
      width: 5,
      color: "#586477"
    },
    fill: "#e8eff7"
  }));
}

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.material.mobile.min.css" />
<base href="http://demos.telerik.com/kendo-ui/diagram/events">


<input type="button" class="btn btn-warning" value="Circle" onclick="drawCircle();" />
<div id="diagram"></div>

最佳答案

我认为问题可能是由于您将JS代码放在HTML之后而引起的。即</body>标记结束后。这可能会导致问题。

在此有效的DEMO中,我已将所有JS代码放入<head>标记中,现在已成功调用函数dramCircle()

08-18 22:28