<?php
$conn = mysqli_connect("localhost","root","","test");
$clid= 'xxxxxxxx';
$result = $conn->query("SELECT clicks, impressions,date FROM reportbydate WHERE clientid='$clid'");
$table = array();
$table['cols'] = array(
array('label' => 'clicks','type' => 'number'),
array('label' => 'impressions','type' => 'number')
);
$rows = array();
while ($nt = $result->fetch_assoc())
{
$temp = array();
$temp[] = array('v' => $nt['clicks'], 'f' =>NULL);
$temp[] = array('v' => $nt['impressions'], 'f' =>NULL);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>
<html>
<head>
<script type="text/javascript">
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawLineColors);
function drawLineColors() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Date');
data.addColumn('number', 'Clicks');
data.addColumn('number', 'Impressions');
data.addRows([JSON.parse(<?php echo json_encode($jsonTable);?>)]);
var options = {
hAxis: {
title: 'Date'
},
vAxis: {
title: 'Clicks vs Impressions'
},
colors: ['#a52714', '#097138']
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px"></div>
</body>
</html>
</script>