I tried creating google chart with values retrieved from database table using PHP , my database gets connected but am getting an error like "Cannot read property 'datefield' of undefined"
my database table contain two columns 'Row Labels (VARCHAR)', 'Sum of No in Rows (INT)' . I don't understand why am getting that error .
<?php
$connection = mysqli_connect('localhost', 'root', '', 'testingoforiginal');
$result = mysqli_query($connection, "SELECT * FROM ba");
if($result){
echo "CONNECTED";
}
?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawStuff);
function drawStuff() {
var data = new google.visualization.arrayToDataTable([
['Row Labels', 'Sum of No in Rows'],
<?php
if(mysqli_num_rows($result) > 0 ){
while($row = mysqli_fetch_array($result)){
echo"['".$row['Row Labels']."',[".$row['Sum of No in Rows']."]],";
}
}
?>
]);
var options = {
title: 'BA',
width: 900,
legend: { position: 'none' },
chart: { title: 'BA',
subtitle: ' ' },
bars: 'horizontal', // Required for Material Bar Charts.
axes: {
x: {
0: { side: 'top', label: 'Sum of No in Rows'} // Top x-axis.
}
},
bar: { groupWidth: "90%" }
};
var chart = new google.charts.Bar(document.getElementById('top_x_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="top_x_div" style="width: 900px; height: 500px;"></div>
</body>
</html>