Issue exporting Google chart to PDF using mpdf

Viewed 320

I created a graph with google charts with the below code:

<script>
var holderarray = [
    ['Question', '% Scores'], ['Question 1', 67], ['Question 2', 18], ['Question 3', 40], ['Question 4', 66], ['Question 5', 37], ['Question 6', 98], ['Question 7', 50], ['Question 8', 75], ['Question 9', 66], ['Question 10', 37]
  ];
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawMaterial);

function drawMaterial() {
    var data = google.visualization.arrayToDataTable(holderarray);
    var materialOptions = {
        colors: ['#15e01b'],
        chart: {
          title: 'Value selected'
        },
        hAxis: {
          title: '% Score',
          minValue: 0, maxValue: 100
        },
        vAxis: {
          title: 'Questions'
        },
        bars: 'horizontal'
    };
    
    var chart_div = document.getElementById('chart_div');
    var chart = new google.visualization.BarChart(chart_div);

    // Wait for the chart to finish drawing before calling the getImageURI() method.
    google.visualization.events.addListener(chart, 'ready', function () {
        chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
        //console.log(chart_div.innerHTML);
    });

    chart.draw(data, google.charts.Bar.convertOptions(materialOptions));
}
<div id='chart_div' style='height:300px;'></div>

This works fine, Now trying to export this graph using MPDF, I put the DIV to display the graph in my $html variable to export to PDF like below:

include("mpdf/mpdf.php");
$mpdf=new mPDF(); 

$html = "
Testing PDF Creator<br>
<div id='chart_div' style='height:300px;'></div>
";

echo "$html";

$mpdf->WriteHTML($html);
$mpdf->Output();
$mpdf->debug = true;
exit

the echo still shows the graph but the PDF generated contain only "Test PDF Creator" no graph. I have search through a lot of fix but non simce to work at all... Please healp

0 Answers
Related