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

263
Visualizações
Definir backgroundColor a partir de datos en chartJS

¿Cómo configuro el color de fondo de un elemento usando un atributo de una variable de datos?

"backgroundColor": ["Farbe"], no funcionará...

Es decir. ¿Cómo accedo a la información proporcionada en la variable?

¡Muchas gracias!

https://jsfiddle.net/zre6t1jn/

 var mydata = [ { "Thema": "Thema 1", "Anzahl": 50, "Farbe": "#006aaa" }, { "Thema": "Thema 2", "Anzahl": 10, "Farbe": "#0071ae" }, { "Thema": "Thema 3", "Anzahl": 10, "Farbe": "#0077b1" }, { "Thema": "Thema 4", "Anzahl": 5, "Farbe": "#007cb3" } ]; var lineCtx = document.getElementById("myChartTree"); var myLineChart = new Chart(lineCtx, { "type": "treemap", "options": { "responsive": true, "plugins": { "title": { "display": false, }, "legend": { "display": false } } }, "data": { "datasets": [{ "tree": mydata, "key": "Anzahl", "groups": ["Thema"], "borderWidth": 2, "borderColor": "white", ---> **"backgroundColor": "#cccccc",** <--- "spacing": 0, "labels": { "display": true, "font": { "size": 11 } } }] } } );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Puede usar una opción programable para esto como color de fondo:

 var mydata = [{ "Thema": "Thema 1", "Anzahl": 50, "Farbe": "#006aaa" }, { "Thema": "Thema 2", "Anzahl": 10, "Farbe": "#0071ae" }, { "Thema": "Thema 3", "Anzahl": 10, "Farbe": "#0077b1" }, { "Thema": "Thema 4", "Anzahl": 5, "Farbe": "#007cb3" } ]; var lineCtx = document.getElementById("myChartTree"); var myLineChart = new Chart(lineCtx, { "type": "treemap", "options": { "responsive": true, "plugins": { "title": { "display": false, }, "legend": { "display": false } } }, "data": { "datasets": [{ "tree": mydata, "key": "Anzahl", "groups": ["Thema"], "borderWidth": 2, "borderColor": "white", "backgroundColor": (ctx) => (ctx.dataIndex ? mydata[ctx.dataIndex].Farbe : 'gray'), "spacing": 0, "labels": { "display": true, "font": { "size": 11 } } }] } } );
 <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>= <script src="https://cdn.jsdelivr.net/npm/chartjs-chart-treemap@2.0.2/dist/chartjs-chart-treemap.js"></script> <div style="width:auto;max-width: 100%;height:200px;"> <canvas id="myChartTree" width="507px" height="200px"></canvas> </div>

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