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

163
Vistas
Dictionary in react js

I'm creating an interactive viz with React and I would like to add a slider in my viz.

import "./styles.css";
import React from "react";
import Sunburst from "react-zoomable-sunburst";
import { data } from "./data";
import { Slider } from "@mui/material";

class App extends React.Component {
  onSelect(event) {
    console.log(event);

    const obj = {
      e: 2016,
      d: 2017,
      c: 2018,
      b: 2017,
      a: 2016
    };

    console.log("Object.entries");
    console.log(Object.entries(obj));
  }

  render() {
    return (
      <div className="App">
        <Sunburst
          width="400"
          height="400"
          data={data.a}
          count_member="size"
          labelFunc={(node) => node.data.name}
          _debug={false}
        />
        <Slider
          aria-label="Year"
          defaultValue={2016}
          valueLabelDisplay="auto"
          step={1}
          marks
          min={2016}
          max={2020}
        />
      </div>
    );
  }
}

export default App;

Above is my code. I added my data from 2016 to 2020 in data.js file and I want my viz to change according to the year as I move my slider.

  a: {
    name: "2016",
    children: [
      {
        name: "Campus",
        children: [
          {
            name: "Liabilities",
            children: [
              {
                name: "Current Liabilities",
                children: [
                  { name: "Accounts payable", size: 53010 },
                  { name: "Accrued salaries", size: 23554 },
                  { name: "Unearned revenue", size: 253322 },
                  { name: "Commercial paper", size: 326008 },
                  { name: "Current portion of long-term debt", size: 112431 },
                  { name: "Funds held for others", size: 2500 },
                  { name: "Other current liabilities", size: 71036 }
                ]
              }

This is a part of my code in data.js and I named 2016 data as a, 2017 as b, and so on. I wanted to name as 2016, 2017... instead of a,b... but this didn't work since data.2016 didn't work. (So I made it data.a in the code above). I tried data['2016'] instead of data.a but this came out with the error: /src/App.js: JSX value should be either an expression or a quoted JSX text (17:15).

So currently, my slider doesn't work. I created the dictionary in the code above but not sure what to do with the dictionary (I'm not that familiar to React js) Is there any way to use dictionary or other method in React to resolve this problem?

Thanks.

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