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

104
Visualizações
I would like to only select the second object in an array within a map function

so I created a bar chart using Chart Js. So by using props I would like to change the labels of datasets one and two. The thing is my prop is set up in such a way due to the use in other graphs, that they have two objects inside. I only want to use, for example, object 2(in the object array) name for dataset two's label. I hope this makes sense.

I know you can use the map function to take all the object names, but I only want one..

                datasets: [
              {
                label: props.data.map((o) => o.Name),
                data: props.data.map((o) => o.Size),
                borderColor: 'rgba(181, 156, 201, 1)',
                backgroundColor: 'rgba(181, 156, 201, 0.75)'

              },
              {
                label: props.data.map((o) => o.Name),
                data: props.data.map((o) => o.Size),
                borderColor: 'rgba(131, 90, 165, 1)',
                backgroundColor: 'rgba(131, 90, 165, 0.75)',
              },

What the set up above gives me Bar Chart with two datasets

This is my useState set

            setObjectOneIfo([InfoOne, InfoTwo])

And this is what I get in my console What I get in my console

Maybe I'm missing something. Any help would be largely appreciated.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

          datasets: [
              {
                  label: props.data.map((o) => o.Name[1]), //Just put the index number you want behind name in square brackets
                  data: props.data.map((o) => o.Size),
                  borderColor: 'rgba(181, 156, 201, 1)',
                  backgroundColor: 'rgba(181, 156, 201, 0.75)'

              },
              {
                 label: props.data.map((o) => o.Name),
                 data: props.data.map((o) => o.Size),
                 borderColor: 'rgba(131, 90, 165, 1)',
                 backgroundColor: 'rgba(131, 90, 165, 0.75)',
              }
about 4 years ago · Santiago Trujillo 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