Add link labels dynamically

Hi,
I have extended the link data array myDiagram.model.linkDataArray in the flowchart example by adding one additional column that contains the value of a link label. For example, a row in the new array (called myLinkDataArray) looks like:
{from: -2, to: -10, points: E, __gohashid: 1696, 'link text'}
Now I would like to display the link text on the link itself in the diagram. I tried to do this with myDiagram.model.setDataProperty but unfortunately I didn’t know how to do it.
Would you please advise on how to iterate over the new link array myLinkDataArray and show the link label above each corresponding link?
Thanks !

First, the JavaScript you quoted is not valid syntax – there is no property name for your additional property.

Second, do not include “__gohashid” in your properties.

Third, to add properties to existing link data objects programmatically, do something like:

model.commit(function(m) {
  m.linkDataArray.forEach(function(ld) {
      m.set(ld, "text", ... some label text ...);
    });
});

Here I am assuming your new data property name is “text”, but you can choose whatever name you like, as long as you use it as the source property name in a Binding on some TextBlock.text property in the Link template.

If you are not modifying existing link data in memory, but are still in the phase where you a building the model data, i.e. before assigning the Array to GraphLinksModel.linkDataArray, then you don"t need to involve the model which probably does not yet exist.

Thank you for your reply and your comments.
Is it necessary for a property such as “text” to be bound to a property in linkDataArray? can’t it be bound to a custom property in a custom array that has nothing to do with GoJS such as myLinkDataArray?

I do not understand the situation that you are describing. If the data is not used by GoJS, then it does not matter to GoJS what properties it has.