Search code examples
powerbivisualizationpowerbi-desktopvega-litedeneb

Pie Chart Vega Lite : Conditional Slice colors


I would like the pie slices to be colored with the PowerBI scheme color except for the "other players" section which needs to be always grey.

[My Pbx link]https://1drv.ms/u/s!An2aQoxg76Kv6jnMWzcGS6aWvMr9?e=kEt8cY

Thanks in advance.


Solution

  • enter image description here

    {
      "width": "container",
      "height": "container",
      "data": {"name": "dataset"},
      "encoding": {
        "theta": {
          "field": "Points_calculation",
          "type": "quantitative",
          "stack": true
        },
        "order": {
          "field": "ORDER",
          "type": "quantitative",
          "sort": "descending"
        },
        "color": {
          "field": "Name",
          "type": "nominal",
          "sort": {
            "field": "ORDER",
            "order": "descending"
          },
          "legend": null, 
           "scale": {"scheme": "pbiColorNominal"}
        }
      },
      "layer": [
        {
          "name": "******RING BACKGROUND******",
          "mark": {
            "type": "arc",
            "outerRadius": 100
          }
        },
        {
          "mark": {
            "type": "arc",
            "outerRadius": 100, "fill":{"expr":"datum.Name =='Other players'?'grey':''"}
          }
        },
        {
          "name": "******Name labels******",
          "mark": {
            "type": "text",
            "radius": 115,
            "dy" : 4,
            "fill": "black",
            "align": {
              "expr": "scale('theta', datum.Points_calculation_end) > PI ?'right':'left'"
            }
          },
          "encoding": {
            "text": {
              "field": "Name",
              "type": "nominal"
            }
          }
        },
        {
          "name": "******Values_Labels******",
          "mark": {
            "type": "text",
            "radius": 80,
            "fill": "black"
          },
          "encoding": {
            "text": {
              "field": "Points_calculation",
              "type": "nominal"
            }
          }
        }
      ]
    }