I am trying to generate image of my charts from my local server(I've installed highcharts on it).
Following is the code
var chart = Highcharts.charts[i];
var render_width = chart.chartWidth;
var render_height = chart.chartHeight;
// Get the cart's SVG code
var svg = chart.getSVG({
exporting: {
sourceWidth: chart.chartWidth,
sourceHeight: chart.chartHeight
}
});
// Create a canvas
var canvas = document.createElement('canvas');
canvas.height = render_height;
canvas.width = render_width;
document.body.appendChild(canvas);
// Create an image and draw the SVG onto the canvas
var image = new Image;
image.onload = function() {
canvas.getContext('2d').drawImage(this, 0, 0, render_width, render_height);
console.log(image.src);
afterPlotExport();
};
image.src = 'data:image/svg+xml;base64,' + window.btoa(svg);
}
When i'm trying to log inside onload() function i'm expecting a base64 string.But the string which is generated appears as broken image when i copy paste it to an online base64 to image converter.
Any help would be appreciated as to why the image is appearing broken?