Custom fill of nodeTemplate

Hi, I have nodeTemplate config below:

(go.Panel, 'Auto', { stretch: go.GraphObject.Horizontal }, (go.Shape,
{ fill: ‘#4dbd74’, stroke: null, height: 35 }),
$(go.TextBlock,
{
alignment: go.Spot.Center,
},
new go.Binding(‘text’, ‘label’))),

In fill property, how can i set color’ code base on key of node, ex:

$(go.Shape,
{ fill: key===‘Alpha’ ? ‘4dbd74’ : ‘black’ , stroke: null, height: 35 }),

  • nodeDataArray: [
    {
    key: ‘Alpha’, label: ‘Alpha’,
    },
    {
    key: ‘Beta’, label: ‘Beta’,
    },
    ];

Thanks a lot !

Use a Binding on the Shape targeting the Shape.fill property, with the source being the “key” property, using a conversion function that checks the key value and returns the desired color.
Please read GoJS Data Binding -- Northwoods Software

1 Like

Thank you for a quickly support!