两个实例代码 放在最下面
官方文档: Production Process Viewer
中文文档: GoJS 图形组件简介 | GoJS
如果想去掉 左上角水印 可以下载 2.1.48 版本 网上去除这个版本水印的方法比较多
npm i gojs -S
import go from 'gojs' //在export default前
他类似于 echarts 需要一个盒子装载
<div class="inCharts" id="myDiagramDiv">
div>
var myDiagram = $(go.Diagram, "myDiagramDiv",//为DIV.HTML元素创建一个画布
{
//设置画布配置
initialAutoScale: go.Diagram.Uniform, // 缩放以显示所有内容
maxSelectionCount: 1, // 不要让用户一次选择多于一个的东西
isReadOnly: true, // 只读 不可拖动
contentAlignment: go.Spot.Center, // 位置在中间
// layout: $(go.TreeLayout,
// { angle: 90, layerSpacing: 35 })
});
比方做成官网这种动态线
myDiagram.linkTemplate =
$(go.Link,
{
layerName: "Background",
routing: go.Link.Orthogonal,
corner: 15,
reshapable: true,
resegmentable: true,
},
$(go.Shape, new go.Binding("stroke", "color"), { isPanelMain: true, strokeWidth: 10 }),
$(go.Shape, { isPanelMain: true, stroke: "white", strokeWidth: 3, name: "PIPE", strokeDashArray: [20, 40] })
);
var opacity = 1;
var down = true;
function loop() {
var diagram = myDiagram;
setTimeout(() => {
var oldskips = diagram.skipsUndoManager;
diagram.skipsUndoManager = true;
diagram.links.each(link => {
var shape = link.findObject("PIPE");
var off = shape.strokeDashOffset - 3;
// animate (move) the stroke dash
shape.strokeDashOffset = (off <= 0) ? 60 : off;
// animte (strobe) the opacity:
if (down) opacity = opacity - 0.01;
else opacity = opacity + 0.003;
if (opacity <= 0) { down = !down; opacity = 0; }
if (opacity > 1) { down = !down; opacity = 1; }
shape.opacity = opacity;
});
diagram.skipsUndoManager = oldskips;
loop();
}, 60);
}
loop()
myDiagram.nodeTemplate = $(go.Node, "auto",)
$(go.Panel,) // 相当于一个div
$(go.Picture,) // 图片
$(go.TextBlock) // 文本
$("Button") // 按钮
每个节点下方的内容会不同 这个时候就出现了节点这个概念
var itemtemplates = new go.Map()
// 如果状态为pic 则新增一个图片
itemtemplates.add("pic",
$(go.Panel,
$(go.Picture,
{ margin: 10, width: 30, height: 30, background: 'transparent' },
new go.Binding("source")))
);
// 如果状态为text 则新增一个文本
itemtemplates.add("text",
$(go.Panel,
$(go.TextBlock,
new go.Binding("text"))
));
数据
diagram.model = new go.GraphLinksModel( [
{ key: "Alpha",
info: [
{ type: "text", text: "some text" },
{ type: "button", text: "Click me!", handler: "alert"}
]
},
{ key: "Beta",
info: [
{ type: "text", text: "first line" },
{ type: "button", text: "First Button", handler: "alert"},
{ type: "text", text: "second line" },
{ type: "button", text: "Second Button", handler: "alert" }
]
}
],[
{ from: "Alpha", to: "Beta" }
]);
diagram.model.nodeDataArray = [
{ key: "Alpha", isGroup: true },
{ key: "Beta", group: "Alpha" },
{ key: "Gamma", group: "Alpha", isGroup: true },
{ key: "Delta", group: "Gamma" },
{ key: "Epsilon", group: "Gamma" },
{ key: "Zeta", group: "Alpha" },
{ key: "Eta", group: "Alpha", isGroup: true},
{ key: "Theta", group: "Eta" }
];
组样式 当在数据中 这行数据设置了 isGroup: true 则他使用的样式为下方
diagram.groupTemplate =
$(go.Group, "Vertical",
$(go.Panel, "Auto",
$(go.Shape, "RoundedRectangle", // 围绕着占位符Placeholder
{ parameter1: 14,
fill: "rgba(128,128,128,0.33)" }),
$(go.Placeholder, //占位符,表示所有构件的面积,
{ padding: 5}) // 添加内边距
),
$(go.TextBlock, // group title
{ alignment: go.Spot.Right, font: "Bold 12pt Sans-Serif" },
new go.Binding("text", "key"))
);
名称
相
A
B
C
总
电流(A)
{{ tableData.ycIa }}
{{ tableData.ycIb }}
{{ tableData.ycIc }}
-
电压(V)
{{ tableData.ycUa }}
{{ tableData.ycUb }}
{{ tableData.ycUc }}
-
电压(V)
AB/BC/CA
{{ tableData.ycUab }}
{{ tableData.ycUbc }}
{{ tableData.ycUca }}
-
有功功率(kW)
{{ tableData.ycPa }}
{{ tableData.ycPb }}
{{ tableData.ycPc }}
{{ (tableData.ycPa + tableData.ycPb + tableData.ycPc).toFixed(2) }}
无功功率(kVar)
{{ tableData.ycQa }}
{{ tableData.ycQb }}
{{ tableData.ycQc }}
{{ (tableData.ycQa + tableData.ycQb + tableData.ycQc).toFixed(2) }}
{{ form.thisYearTotal }}
{{ form.thisYearLoss }}
{{ form.temperature }}
{{ form.humidity }}
名称
相
A
B
C
总
电流(A)
{{ form.yc_ia }}
{{ form.yc_ib }}
{{ form.yc_ic }}
-
电压(V)
{{ form.yc_ua }}
{{ form.yc_ub }}
{{ form.yc_uc }}
-
电压(V)
AB/BC/CA
{{ form.yc_uab }}
{{ form.yc_ubc }}
{{ form.yc_uca }}
-
有功功率(kW)
{{ form.yc_pa }}
{{ form.yc_pb }}
{{ form.yc_pc }}
{{ (form.yc_pa + form.yc_pb + form.yc_pc).toFixed(2) }}
无功功率(kVar)
{{ form.yc_qa }}
{{ form.yc_qb }}
{{ form.yc_qc }}
{{ (form.yc_qa + form.yc_qb + form.yc_qc).toFixed(2) }}