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

152
Visualizações
d3 grouped stacked column chart

I have the following object structure:

date: 01.01.2022,
type: 1,
property: a
value: 0
},{
date: 01.01.2022,
type: 1,
property: b
value: 2
},{
date: 01.01.2022,
type: 2,
property: a
value: 10
},{
date: 02.01.2022,
type: 1,
property: a
value: 0
},{
date: 02.01.2022,
type: 1,
property: b
value: 2
},{
date: 02.01.2022,
type: 2,
property: a
value: 50
},
]

I want to generate a grouped stacked column-chart with this data, where the date defines the category on the x-axis, type represents a group and properties are represented by stacks.

let categoryNames = data.map(function (d) { return d.date });
let groupNames = data.map(function (d) { return d.type] });
let stackNames = data.map(function (d) { return d.property] });
x0.domain(categoryNames);
x1.domain(groupNames).rangeRound([0, x0.bandwidth()]);
[...]
g.append("g")
      .selectAll("g")
      .data(data)
      .enter().append("g")
      .attr("fill", function (d) { return z(d.key); })
      .selectAll("rect")
      .data(d3.stack().keys('property')(data))
      .enter().append("rect")
      .attr("x", function (d) { return x0(d.date]); })
      .attr("y", function (d) { return y(d['value']) })
      .attr("height", function (d) {
        return ((height - y(0)) > 0 ? (height - y(0)) : 0);
      })

I tried the solution from Kyros Koh mentioned here: How to make grouped stacked bar chart in d3js? https://jsfiddle.net/46em2svg/ but there is an error with .stackedBars with d3-version 5.x and I couldn't fix it.

d3.rollup() or d3.group() dont work on this object structure. Do you have any suggestions how I can implement a grouped and stacked column chart with this object structure or how I can redefine the object-structure without bloating the data-structure?

Thanks for your help in advance.

about 4 years ago · Juan Pablo Isaza
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