Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda