I need help to export the google chart graph to pdf or put a button that
generates the pdf of the graph. Does anyone know how to do?
My code looks like this:
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Element", "Quantidade de Mudas", { role: "style" } ],
<?php
foreach ($relatorios as $value) {
echo '["'.$value['cidade'].'" , '.$value['quantidade'].' ,
""],';
//echo 'R$' . number_format($num, 2, ',', '.');
}
?>
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" },
2]);
var formatter = new google.visualization.NumberFormat(
{negativeColor: 'red', negativeParens: true, pattern:
'###.###'}); formatter.format(data, 1); formatter.format(data, 1);
var options = {
title: "Total de mudas por cidade",
width: 1560,
height: 2550,
bar: {groupWidth: "40%"},
legend: { position: "none" },
pieSliceText: 'value'
};
var chart = new
google.visualization.BarChart(document.getElementById("barchart_values",
"myChart"));
chart.draw(view, options);
$('button').on('click', function() {
html2canvas($('#myChart'), {
onrendered: function(canvas) {
var imgData = canvas.toDataURL('image/png');
var pdf = new jsPDF('p', 'mm');
pdf.addImage(imgData, 'PNG', 10, 10);
pdf.save('test.pdf');
}
});
});
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/f941326f-5a69-4c6f-b6d1-fc3ac3bd197d%40googlegroups.com.