Since I am new to Google charts, I would like to know how to Integrate the GEO chart for states in india in PHP.
The following PHP not working properly.Can anyone correct me where i went wrongly?
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hitech";
$text="";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>
Create Google Charts
</title>
<script type="text/javascript">
google.load("visualization", "1", {packages:["geochart"]});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['LOCATION', 'Sales value'],
<?php
//$query = "SELECT count(ip) AS count, country FROM visitors GROUP BY country";
$query = "SELECT SUM(AMOUNT) AS count, LOCATION FROM SALES_DATA GROUP BY LOCATION ORDER BY LOCATION";
$exec = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".$row['LOCATION']."',".$row['count']."],";
}
?>
]);
var options = {
region: 'IN', // India
displayMode: 'markers', //If you want to highlight some cities
resolution: 'provinces', //If you want to display provinces in India
colorAxis: {colors: ['blue']} //If you want specific color for your markers (cities)
};
var chart = new google.visualization.GeoChart(document.getElementById('geochart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<h3>Geo Chart</h3>
<div id="geochart" style="width: 900px; height: 500px;"></div>
</body>
</html>