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

243
Visualizações
Creating dictionary in React

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);
  }
  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: "2020",
    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) So currently, my slider doesn't work. Is there any way to make dictionary or other method in React to resolve this problem?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

use

data['2016']

That should work.

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