chartjs-node icon indicating copy to clipboard operation
chartjs-node copied to clipboard

Window is undefined?

Open ColeT3tr3x opened this issue 6 years ago • 0 comments

Hello! So, I have tried to use ChartJS on it's on package with no luck so I tried the this package but seem to be running into an error.

Here is my code:

`` const canvas = Canvas.createCanvas(800, 450); const ctx = canvas.getContext('2d');

var myChart = new Chart(ctx,{
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255,99,132,1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          beginAtZero:true
        }
      }]
    },
    responsive: false
  }
});


const ChartjsNode = require('chartjs-node');
var chartNode = new ChartjsNode(600, 600);
return chartNode.drawChart(myChart)
.then(() => {
    return chartNode.getImageBuffer('image/png');
})
.then(buffer => {
    Array.isArray(buffer) // => true
    return chartNode.getImageStream('image/png');
})
.then(streamResult => {
    streamResult.stream // => Stream object
    streamResult.length // => Integer length of stream
    return chartNode.writeImageToFile('image/png', './testimage.png');
})
.then(() => {
  Canvas.loadImage('./testimage.png').then(async hydra => {
    ctx.drawImage(hydra, 0, 0, canvas.width, canvas.height);``

Error is : ReferenceError: window is not defined

Any ideas?

ColeT3tr3x avatar Dec 07 '18 12:12 ColeT3tr3x