Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!