Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
DW868990
Helper IV
Helper IV

VEGA - Formatting of links between nodes

Hi,
I have created a tree visualisation in VEGA within the deneb visual, and i am just looking for a little bit of VEGA help as i am currently on the learning curve of from Vega-Lite to Vega.

DW868990_0-1715784940163.png

 

Now basically what i am trying to achieve is to format the color or the dash of the links between nodes based on a field in my data, the field is called relationship.
For example when the relationship field is X, i need the link between nodes to either be dashed or red. 

The snippet of VEGA below is the path mark that i used to create the links between nodes.

{
"type": "path",
"from": {"data": "links"},
"encode": {
"update": {
"path": {"field": "path"},
"stroke": {"value": "#ccc"}
}
}
},


Any help is very much appreciated.

@giammariam not sure if this is something you could lend any advice to, TIA.

 

 

 




1 ACCEPTED SOLUTION
v-jianpeng-msft
Community Support
Community Support

Hi, @DW868990 

Maybe you can try the following VEGA code:

{
  "type": "path",
  "from": {"data": "links"},
  "encode": {
    "update": {
      "path": {"field": "path"},
      "stroke": {
        "condition": [
          {"test": "datum.relationship == 'X'", "value": "red"},
          {"test": "datum.relationship == 'Y'", "value": "blue"} // Example for another condition
        ],
        "value": "#ccc" // Default color
      },
      "strokeDash": {
        "condition": [
          {"test": "datum.relationship == 'X'", "value": [5, 5]} // Example for dashed line
        ],
        "value": null // Default to solid line
      }
    }
  }
}

 It is recommended that you read the official VEGA tutorial:

Tutorials | Vega

vjianpengmsft_0-1715832075023.png

As you learn VEGA, we recommend that you read up on other excellent VEGA code:

Vega Data Visualization Examples - Power of Business Intelligence (powerofbi.org)

vjianpengmsft_1-1715832158112.png

Explore examples and get inspired | Observable (observablehq.com)

vjianpengmsft_2-1715832224337.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-jianpeng-msft
Community Support
Community Support

Hi, @DW868990 

Maybe you can try the following VEGA code:

{
  "type": "path",
  "from": {"data": "links"},
  "encode": {
    "update": {
      "path": {"field": "path"},
      "stroke": {
        "condition": [
          {"test": "datum.relationship == 'X'", "value": "red"},
          {"test": "datum.relationship == 'Y'", "value": "blue"} // Example for another condition
        ],
        "value": "#ccc" // Default color
      },
      "strokeDash": {
        "condition": [
          {"test": "datum.relationship == 'X'", "value": [5, 5]} // Example for dashed line
        ],
        "value": null // Default to solid line
      }
    }
  }
}

 It is recommended that you read the official VEGA tutorial:

Tutorials | Vega

vjianpengmsft_0-1715832075023.png

As you learn VEGA, we recommend that you read up on other excellent VEGA code:

Vega Data Visualization Examples - Power of Business Intelligence (powerofbi.org)

vjianpengmsft_1-1715832158112.png

Explore examples and get inspired | Observable (observablehq.com)

vjianpengmsft_2-1715832224337.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.