I am creating a highchart client side. What I need to do is to get a png of that chart and store it server side.
Currently, I have produced the highchart, got the SVG and converted it to a PNG (shown below):
function saveThumbnail(graph_name, chart) {
canvg(document.getElementById(graph_name + '_thumb'), chart.getSVG());
var chart_Canvas = document.getElementById(graph_name + '_thumb');
var chart_Img = chart_Canvas.toDataURL("image/png");
$('#graph_name').val(graph_name);
$('#graph_png').val(chart_Img);
$('#imageForm').submit();
}
This is my #imageForm:
<form action="/overview" id="imageForm" method="post">
<input id="graph_name" name="graph_name" type="hidden" value=""/>
<input id="graph_png" name="graph_png" type="hidden" value=""/>
</form>
So I have set the value of the PNG to that input which was what was suggested here and I have posted that value back to the server.
Server side:
In the function below, I am trying to create/write to a file with the name of the graph PNG sent back and trying to write that PNG into that file.
function createFiles(graphName, graphPNG, callback) {
fs.writeFile(graphDir + graphName + ".png", graphPNG, function(err) {
if (err) {
console.log(err);
} else {
console.log('File was saved!');
}
});
callback(body);
}
Is there anyway to achieve this?
Note: Cannot have the highcharts server side. It was a decision made earlier and we are unable to go back.