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.