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

92
Visualizações
Json variable not redefining itself after being updated

I was triying to make a discord bot showing information with a chart(chart.js), the i tried making another command that did the same but shortening to the final moments of the chart, the data from the chart comes from a json file, after the data get shortened and the function ends the json variable doesn't redefine itself(first line) as it should.

    async function graficarc() {
    const datos = require('A:/OneDrive/bot generico/graficos/grafico.datos.json')//datos gets defined from json
    const width = 1800
    const height = 1000
    const backgroundColour = 'white'

    const canvas = new ChartJSNodeCanvas({width, height, backgroundColour})
    datos["labels"] = datos["labels"].splice(214)//data gets shortened with splice()
    for (let i = 0; i < 3; i++) {
        datos["datasets"][i]["data"] = datos["datasets"][i]["data"].splice(215)
    }
      const configuration = {
        type: 'line',
        data: datos//data gets used
    }
    console.log(datos)
    const image = await canvas.renderToBuffer(configuration)
      const attachment = new Discord.MessageAttachment(image)
      return attachment
}

Weirdly, this same error affects the original chart function (without getting shortened) and gets is shortened.

Code from original chart:

async function graficar() {
const datos = require('A:/OneDrive/bot generico/graficos/grafico.datos.json')
const width = 1800
const height = 1150
const backgroundColour = 'white'

const canvas = new ChartJSNodeCanvas({width, height, backgroundColour})

  const configuration = {
    type: 'line',
    data: datos
}
  const image = await canvas.renderToBuffer(configuration)
  const attachment = new Discord.MessageAttachment(image)
  return attachment

}

The behavior of the error makes me think that the json file is getting updated, but is not.

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