我正在使用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");
但是之后,我的图表没有显示出来。控制台中也没有错误信息。我应该为节点设置新的形状吗?还是有其他方法可以解决这个问题?谢谢您的帮助!
new go.Binding("fill", "color")
。 - Simon Sarris