gpt4 book ai didi

javascript - GoJS:如何更改节点填充颜色?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:42:05 24 4
gpt4 key购买 nike

我正在使用 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" }];

然后将绑定(bind)添加到 textBlock 为

 $(go.Shape, "RoundedRectangle", {
fill: "#cce6ff" // the default fill, if there is no data-binding
}, new go.Binding("fill", "fill"))
 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:如何更改节点填充颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41367434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com