javascript - 用 XML 在 mxGraph 中画线?
问题描述
我使用这个 mxGraph 编辑器的例子
我正在尝试使用该库来制作梯形图编辑器,所以我想绘制起点和终点线,但我需要它们作为图表区域从左到右的边界(每次都从编辑器开始) ,我该怎么做?如何让它们连接到元素?
有人可以帮忙吗?
编辑:
这段代码画了一条线,然后我用几何属性定位它。
var xml = "<root>"+
"<MyObject id=\"2\">"+
"<mxCell style=\"strokeColor=black;fillColor=black\" parent=\"1\" vertex=\"1\" type = 'startLine'>"+
"<mxGeometry x=\"0\" y=\"0\" width=\"2\" height=\"119\" as=\"geometry\"/>"+
"</mxCell></MyObject></root>";
doc = mxUtils.parseXml(xml),
codec = new mxCodec(doc),
elt = doc.documentElement.firstChild,
cells = [];
while (elt != null){
cells.push(codec.decodeCell(elt));
elt.setAttribute('attribute1', 'value1');
$this.editor.graph.refresh();
elt = elt.nextSibling;
}
$this.editor.graph.addCells(cells);
解决方案
为了将问题标记为“已回答”,以便其他人可以看到:
做这个 :
var xml = "<root>"+
"<MyObject id=\"2\">"+
"<mxCell style=\"strokeColor=black;fillColor=black\" parent=\"1\" vertex=\"1\" type = 'startLine'>"+
"<mxGeometry x=\"0\" y=\"0\" width=\"2\" height=\"119\" as=\"geometry\"/>"+
"</mxCell></MyObject></root>";
doc = mxUtils.parseXml(xml),
codec = new mxCodec(doc),
elt = doc.documentElement.firstChild,
cells = [];
while (elt != null){
cells.push(codec.decodeCell(elt));
elt.setAttribute('attribute1', 'value1');
$this.editor.graph.refresh();
elt = elt.nextSibling;
}
$this.editor.graph.addCells(cells);
推荐阅读
- java - 为什么未来 .isDone() 必须在 executorService.shutdown() 之后
- reactjs - react中的动态css类
- java - 想要列出内部存储和外部存储上的所有音乐文件,但无法在 Android 10 上完成
- sql - 带删除的内连接
- css - 为什么一个 div 之后
不显示在标题下? - javascript - 选择具有相同类名的动态创建的元素
- javascript - 如何在数组中项目的增加和减少不透明度之间切换?
- google-cloud-platform - 来自 G Suite 的 Google Takeout 从 Google Cloud Storage 下载
- mysql - 列出 table1 中的所有项目并填写 table2 中匹配的信息
- android - 图像未在 ImageView 中加载