stage.image not showing?
I am using the "string" method to create a stage with multiple charts and an image:
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":"#0da6e0","stroke":"#0da6e0"}]}});c0.bounds('5%','5%','90%','25%').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('5%','35%','25%','25%').container(stage);c1.draw();var c2=anychart.fromJson({"chart":{"type":"pie","innerRadius":"0%","data":[{"x":"Apples","value":"28.14","fill":"#92d9ed"},{"x":"Oranges","value":"128.14","fill":"#1c6b8d"}]}});c2.bounds('35%','35%','25%','25%').container(stage);c2.draw();stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);
Any reason why everything but the image appears? No matter what I try, I cannot get the image to show.
@deurloo Probably the image is behind the charts. Try to set higher zIndex to the image like this:
var image = stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);
image.zIndex(10);
Unfortunately that didn't help. Somehow I must be doing something really stupid, because if I remove everything and just leave the image like this:
var stage = anychart.graphics.create("container", 1000, 1000);stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);
It results in an error:
(node:16857) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'replace' of undefined
Which sounds to me like the image is empty or missing, or I am messing up the configuration.
Any suggestions welcome!
@deurloo We have noticed you create stage with the following line:
var stage = anychart.graphics.create("container", 1000, 1000);
Please, try the following line instead:
var stage = acgraph.create("container", 1000, 1000);
If this doesn't help you, please, specify which version of AnyChart you are using. We will try to reproduce the issue and investigate it.
Changing that line produced an error:
(node:12433) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): [object Object]
The versions I am using:
[email protected] [email protected]
Maybe I am doing something wrong?
Basically my script looks like this (abstract):
var anychartExport = require('anychart-nodejs'); var chart = 'var stage = anychart.graphics.create("container");' chart += 'stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);';
anychartExport.exportTo(chart, {outputType: 'pdf'}).then(function(image){ fs.writeFile('anychart.pdf', image, function(err){ if (err) throw(err); console.log('Complete'); process.exit(); }); }, function(err){ if (err) throw(err); process.exit(); });
@deurloo Below you can find the correct script to export stage with an image to JPG. Unfortunately, export to PDF returns a document without the image. But no errors or exceptions occur. It seems to be a bug and we will investigate it. We will notify you when the fix becomes available.
// 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('<body><div id="container"></div></body>', {runScripts: 'dangerously'});
// 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", 1000, 1000);
stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);
anychartExport.exportTo(stage, 'jpg').then(function(image) {
fs.writeFile('anychart.jpg', image, function(fsWriteError) {
if (fsWriteError) {
console.log(fsWriteError);
} else {
console.log('Complete');
}
});
}, function(generationError) {
console.log(generationError);
});
Hi Alexander,
Thanks for confirming. Looking forward to hear the end result.
Marijn
Sent from my iPhone
On 11 Jul 2018, at 06:28, Alexander Shestacov <[email protected]mailto:[email protected]> wrote:
@deurloohttps://github.com/deurloo Below you can find the correct script to export stage with an image to JPG. Unfortunately, export to PDF returns a document without the image. But no errors or exceptions occur. It seems to be a bug and we will investigate it. We will notify you when the fix becomes available.
// 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('
', {runScripts: 'dangerously'}); // 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", 1000, 1000); stage.image("https://vignette.wikia.nocookie.net/newtendo/images/0/08/Mariossbi.png", 10, 10, 200, 200);
anychartExport.exportTo(stage, 'pdf').then(function(image) { fs.writeFile('anychart.pdf', image, function(fsWriteError) { if (fsWriteError) { console.log(fsWriteError); } else { console.log('Complete'); } }); }, function(generationError) { console.log(generationError); });
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/AnyChart/AnyChart-NodeJS/issues/10#issuecomment-404041381, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Am5wgXiH_mmDYvymahql0BYDudwtCP6Eks5uFX7RgaJpZM4VBYr-.
@deurloo The problem comes from restrictions of librsvg library. It can't export raster images from svg to other vector files. We are looking for a solution. We will notify you when the update becomes available.