My code is like this:
<script type="text/javascript">
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Questions', 'Result'],
['Correct Answers', <?= !empty($student_result[0]
['correct_ans_count']) ? $student_result[0]['correct_ans_count'] : '0'; ?>],
['Wrong Answers', <?= !empty($student_result[0]['wrong_ans_count']) ? $student_result[0]['wrong_ans_count'] : '0'; ?>],
['Skipped Questions', <?= !empty($student_result[0]['skiped_que_count']) ? $student_result[0]['skiped_que_count'] : '0'; ?>],
]);
var options = {
title: 'Test Result Piechart',
pieHole: 0.4,
chartArea: {
left: 100,
top: 70,
width: '100%',
height: '80%'
}
};
var chart_area = document.getElementById('piechart');
var chart = new google.visualization.PieChart(chart_area);
google.visualization.events.addListener(chart, 'ready', function()
{
chart_area.innerHTML = '<img src="' + chart.getImageURI() + '" class="img-responsive">';
});
chart.draw(data, options);
}
</script>
My html code is:
<div id="piechart" style="width: 100%; max-width:900px; height: 500px; ">
</div>
when I export to pdf using mpdf using codeigniter 3.x then it wont show graph in pdf.
My php(codeigniter) code is:
$data=array('name'=>'abc');
$html = $this->load->view('view_result',$data,true);
$this->load->library('M_pdf');
$mpdf = new mPDF();
$mpdf->AddPage(
'P', // L - landscape, P - portrait
'', '', '', '', 4, // margin_left
4, // margin right
4, // margin top
4, // margin bottom
4, // margin header
4); // margin footer
// die;
ob_clean();
$mpdf->allow_charset_conversion = true;
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('test.php', 'D');
In view it shows the graph correctly but in pdf there is no graph only blank space is there. In there any solution to show google chart in mpdf. please help thank you.