Search code examples
powerbivisualizationpowerbi-desktopvega-litedeneb

Pie chart Vega LITE - Labels position


_Hi, for each slice, in the middle of its angle, I try to left align labels outside the circle almost like :This try

Seems to be simple, but I struggle to obtain a nice result for the whole labels after many tries... Here is the link of my file : https://1drv.ms/u/s!An2aQoxg76Kv6mUvq5650jFGm1hH?e=XbJ2d1

Thanks in advance for your help !


Solution

  • Update

    enter image description here

    {
      "width": 230,
      "height": 220,
      "data": {"name": "dataset"},
      "encoding": {
        "theta": {
          "field": "Conso_A_Plan_Clé",
          "type": "quantitative",
          "stack": true
        },
        "order": {
          "field": "Conso_A_Plan_Clé",
          "type": "nominal",
          "sort": "descending"
        },
        "color": {
          "field": "Destination",
          "type": "nominal",
          "sort": {
            "field": "ORDER",
            "order": "descending"
          },
          "legend": null,
          "scale": {
            "scheme": "pbiColorNominal"
          }
        }
      },
      "layer": [
        {
          "name": "******RING BACKGROUND GEN COL******",
          "mark": {
            "type": "arc",
            "outerRadius": 60
          }
        },
        {
          "name": "******Name labels******",
          "mark": {
            "type": "text",
            "radius": {
              "expr": "scale('theta', ((datum.Conso_A_Plan_Clé_end - datum.Conso_A_Plan_Clé_start)/2) + datum.Conso_A_Plan_Clé_start ) > PI  ?95:65"
            },
            "baseline": "middle",
            "dy": 0,
            "fill": "black",
            "align": "left",
            "text": {
              "expr": "[datum.Destination,format(datum.Conso_A_Plan_Clé,'.1f')]"
            }
          }
        }
      ]
    }