a good day to all. I was trying to make a pdf file out of my column chart ( google charts), im using jspdf. when i try to make a pdf file out of bar and pie chart seems the code works fine
But when i try to code it on a column chart it wont print pdf
I tried to search on my code but it seems good
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses', 'Profit'],
['2014', 1000, 400, 200],
['2015', 1170, 460, 250],
['2016', 660, 1120, 300],
['2017', 1030, 540, 350]
]);
var options = {
chart: {
title: 'Company Performance',
subtitle: 'Sales, Expenses, and Profit: 2014-2017',
}
};
var chart = new
google.charts.Bar(document.getElementById('columnchart_material'));
var btnSave = document.getElementById('save-pdf');
google.visualization.events.addListener(chart, 'ready', function () {
btnSave.disabled = false;
});
btnSave.addEventListener('click', function () {
var doc = new jsPDF();
doc.addImage(chcolumnchart_material.getImageURI(), 10, 10, 180, 150);
doc.save('chart.pdf');
}, false);
chart.draw(data, google.charts.Bar.convertOptions(options));
}
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js">
</script>
<input id="save-pdf" type="button" value="Save as PDF" disabled />
<div id="columnchart_material" style="width: 800px; height: 500px;"></div>
chart method getImageURI()
is not supported by material charts.
material --> google.charts.Bar
-- packages: ['bar']
you'll need to use a classic chart.
classic --> google.visualization.BarChart
-- packages: ['corechart']
or --> google.visualization.ColumnChart
note: there is a config option to style classic charts similar to material charts...
theme: 'material'