javascript-GoJS:如何更改节点填充颜色?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-GoJS:如何更改节点填充颜色?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2154字,纯文字阅读大概需要4分钟。
内容图文
![javascript-GoJS:如何更改节点填充颜色?](/upload/InfoBanner/zyjiaocheng/667/31567b25a9b545a7baf5da367066b675.jpg)
我正在使用GoJS制作图表.
我的图表配置(来自官方文档的示例):
function init() {
//......
// define the Node template
myDiagram.nodeTemplate =
$(go.Node, "Auto",
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
// define the node's outer shape, which will surround the TextBlock
$(go.Shape, "RoundedRectangle",
{
parameter1: 20, // the corner has a large radius
fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }),
stroke: null,
portId: "", // this Shape is the Node's port, not the whole Node
fromLinkable: true, fromLinkableSelfNode: true, fromLinkableDuplicates: true,
toLinkable: true, toLinkableSelfNode: true, toLinkableDuplicates: true,
cursor: "pointer"
}),
$(go.TextBlock,
{
font: "bold 11pt helvetica, bold arial, sans-serif",
editable: true // editing the text automatically updates the model data
},
new go.Binding("text").makeTwoWay())
);
//......
}
我以以下方式创建节点:
var nodeOperations = new Object();
for (var i = 0; i < countState; i++) {
var json = {'id': i, 'loc': nodesCenters[i].x +' '+nodesCenters[i].y, 'text': markedStateTable['digitStates'][i] + ', ' + markedStateTable['namedStates'][i]};
nodes.push(json);
}
现在,我需要以编程方式更改特定节点的填充颜色.我正在尝试以下代码:
var data = myDiagram.model.findNodeDataForKey(0);
myDiagram.model.setDataProperty(data, "fill", "green");
但是之后,我的图表不会显示.并且控制台中没有错误.我应该为节点设置新形状吗?或者我该怎么做?谢谢您的帮助!
解决方法:
请在nodeArray中指定填充颜色
var nodeDataArray = [
{ key: 1, text: "Name", fill: "#ff5722", stroke: "#4d90fe", description: "geethu" }];
然后添加绑定到textBlock作为
06001
myDiagram.nodeTemplate =
$(go.Node, "Horizontal", {
isTreeExpanded: false,
click: showDetail
},
$(go.Panel, "Auto",
$(go.Shape, "RoundedRectangle", {
fill: "#cce6ff", // the default fill, if there is no data-binding
stroke: "#6699ff",
height: 40,
strokeWidth: 2,
portId: "",
cursor: "pointer", // the Shape is the port, not the whole Node
}, new go.Binding("fill", "fill")),
$(go.TextBlock, {
editable: true
},
new go.Binding("text", "text"))
),
$("TreeExpanderButton", { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top }, { visible: true })
);
内容总结
以上是互联网集市为您收集整理的javascript-GoJS:如何更改节点填充颜色?全部内容,希望文章能够帮你解决javascript-GoJS:如何更改节点填充颜色?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】