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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.