var myapp = angular.module('sampleapp', ["highcharts-ng"]);
myapp.controller('samplecontoller', function ($scope) {
$scope.highchartsNG = {
options: {
chart: {
type: 'bar'
}
},
series: [{
data: [10, 15, 12, 8, 7]
}],
title: {
text: 'bar chart'
},
loading: false
}
$scope.saveAsBinary = function( ){
var svg = document.getElementById('highchartContainer')
.children[0].innerHTML;
canvg(document.getElementById('canvas'),svg);
var img = canvas.toDataURL("image/png"); //img is data:image/png;base64
img = img.replace('data:image/png;base64,', '');
$('#binaryImage').attr('src', 'data:image/png;base64,'+img);
}
});
<div ng-app="sampleapp">
<div ng-controller="samplecontoller">
<button ng-click="saveAsBinary()">Save as Binary</button>
<highchart id="highchartContainer" config="highchartsNG"></highchart>
<canvas id="canvas" width="1000px" height="600px" style="display:none;"></canvas>
<img id="binaryImage"/>
</div>
</div>
External resources loaded into this fiddle: