Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
How to change the color of the text lables of a pie chart in vega-lite

I have this little graph representing a certain data set. As you can see in the code snippet, the text labels are currently displayed in the same color as the pie chart components themselves and are thus invisible when located within the pie chart (you can see this if you change

mark: {type: "text", radius: 70},

to

mark: {type: "text", radius: 120},

as the text labels will then be outside the area of the pie chart arc. Since I want the text labels to appear inside the arcs, I would like them to be black or white. Does anyone happen to know how I may achieve that?

vegaEmbed("#graph", {
  $schema: "https://vega.github.io/schema/vega-lite/v5.json",
  data: {
    values: [{
        event: "a",
        occurances: 28,
      },
      {
        event: "b",
        occurances: 3,
      },
      {
        event: "c",
        occurances: 1,
      },
      {
        event: "d",
        occurances: 3,
      },
      {
        event: "e",
        occurances: 1,
      },
      {
        event: "f",
        occurances: 10,
      },
      {
        event: "g",
        occurances: 2,
      },
      {
        event: "h",
        occurances: 1,
      },
      {
        event: "k",
        occurances: 1,
      },
    ],
  },
  layer: [{
      mark: {
        type: "arc",
        innerRadius: 50,
        outerRadius: 100
      },
    },
    {
      mark: {
        type: "text",
        radius: 70
      },
      encoding: {
        text: {
          field: "occurances",
          type: "quantitive"
        },
      },
    },
  ],
  mark: {
    type: "arc",
    innerRadius: 50,
    outerRadius: 100
  },
  encoding: {
    color: {
      field: "event",
      type: "nominal",
    },
    theta: {
      field: "occurances",
      type: "quantitative",
      stack: true,
    },
  },
});
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
<div id="graph"></div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Bring the entire encoding outside to keep it common for both layers and provide fill in mark text to apply some color.

Refer below code or editor link:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"event": "a", "occurances": 28},
      {"event": "b", "occurances": 3},
      {"event": "c", "occurances": 1},
      {"event": "d", "occurances": 3},
      {"event": "e", "occurances": 1},
      {"event": "f", "occurances": 10},
      {"event": "g", "occurances": 2},
      {"event": "h", "occurances": 1},
      {"event": "k", "occurances": 1}
    ]
  },
  "encoding": {
    "color": {"field": "event", "type": "nominal"},
    "theta": {"field": "occurances", "type": "quantitative", "stack": true}
  },
  "layer": [
    {"mark": {"type": "arc", "innerRadius": 50, "outerRadius": 100}},
    {
      "mark": {"type": "text", "radius": 70, "fill": "black"},
      "encoding": {"text": {"field": "occurances", "type": "quantitative"}}
    }
  ]
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda