This is my php file it contains three arrays and I am passing these three arrays to external JavaScript file called ss.js
to draw pie chart. If I directly declared array in external JavaScript file it shows the pie chart but when I passing array from php it simply showing nothing. I tried but I can't figure out the error part.
code.php
<?php
$a = array("Apple","Orange","Grape");
$dataArray = array("Task","Hours Per Day");
$arr1 = array("Work","Eat","Commute","Watch TV","Sleep");
$arr2 = array(11,2,2,2,7);
?>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var jArray =<?php echo json_encode($dataArray); ?>;
var jArray1 =<?php echo json_encode($arr1); ?>;
var jArray2 =<?php echo json_encode($arr2); ?>;
</script>
<script type="text/javascript" src="ss.js">
</script>
</head>
<body>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
ss.js
google.load("visualization", "1", {
packages: ["corechart"]
});
function drawData() {
for (var n = 0; n < jArray2.length; n++) {
jArray.push([jArray1[n], parseInt(jArray2[n])]);
}
var data = new google.visualization.arrayToDataTable(jArray);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
google.setOnLoadCallback(drawData);