Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window is undefined? #70

Open
ColeT3tr3x opened this issue Dec 7, 2018 · 0 comments
Open

Window is undefined? #70

ColeT3tr3x opened this issue Dec 7, 2018 · 0 comments

Comments

@ColeT3tr3x
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant