Can't create a chart column
thichpv opened this issue · 2 comments
Why can't I create a chart column
My source:
// require file system and jsdom
var fs = require('fs');
// For jsdom version 10 or higher.
// Require JSDOM Class.
var JSDOM = require('jsdom').JSDOM;
// Create instance of JSDOM.
var jsdom = new JSDOM('
// Get window
var window = jsdom.window;
// require anychart and anychart export modules
var anychart = require('anychart')(window);
var anychartExport = require('anychart-nodejs')(anychart);
var stage = anychart.graphics.create("container");
var c0=anychart.fromJson({"chart":{"title":"Vodafone visits over time","type":"column","series":[{"data":[1,3,6,12,24,4,16,16,17,22,3,2,34,61,63,49,27,4,42,26,26,9,12,2,12,14,42,29,43,3,41,53,75,310,1176,244,144,638,387,270,223,152,105,91,167,175,393,694,704,233,232,527,395,325,414,416,179,186,418,941,351,302,295,142,162,290,221,236,278,839,153,122,193],"fill":"#e01f10","stroke":"#0da6e0"}]}});
c0.bounds(0, 0, 500, 300).container(stage);
c0.draw();
var c1=anychart.fromJson({"chart":{"type":"pie","innerRadius":"0%","data":[{"x":"Apples","value":"18.14","fill":"#0da6e0"},{"x":"Oranges","value":"8.14","fill":"#61c6e5"}]}});
c1.bounds(0, 0, 500, 300).container(stage);
c1.draw();
async function renderChart(chart, img_name){
var chart_img = await anychartExport.exportToSync(chart, 'png');
fs.writeFile(img_name, chart_img, function(fsWriteError) {
if (fsWriteError) {
console.log(fsWriteError);
} else {
console.log('Complete');
}
});
}
renderChart(c0, 'column0.png');
renderChart(c1, 'column1.png');
C1: PIE - Created
C0: Column - Not Create
@thichpv
Please, make sure that you have defined a div container in JSdom in a proper way.
You have provided the following code:
var jsdom = new JSDOM('
', {runScripts: 'dangerously'});
This should be replaced with the following:
var jsdom = new JSDOM('<body><div id="container"></div></body>', {runScripts: 'dangerously'});
If it's ok, please, try to update the imegaMagick
library just like it was described in this issue.
Thanks it worked !