Currently I have an SQL query that reports total views ever and how many total views daily. I am trying to convert this so it uses Google Chart functionality which reports daily and shows the amount of views across a week. I cannot figure out how to do it properly as everytime i kinda get it working, if there is 0 views in a day. That day does not show up so I just need some guidance from an expert. Thanks in advance.
Currently this is how I get the total and daily views code wise:
public function countViews($type_id, $type) // Count all views for specific type
{
$bind = [
':type_id' => $type_id,
':type' => $type
];
$results = $this->db->select('chewi_views','type_id = :type_id AND type = :type', $bind);
$totalRows = count($results);
if($results === FALSE){ $totalRows = '0'; }
return $totalRows;
}
public function countDailyViews($type_id, $type) // Count all daily views for specific type
{
$bind = [
':type_id' => $type_id,
':type' => $type
];
$results = $this->db->select('chewi_views','type_id = :type_id AND type = :type AND cast(date AS DATE) = CURDATE()', $bind);
$totalRows = count($results);
if($results === FALSE){ $totalRows = '0'; }
return $totalRows;
}
And in the database it stores data like this:
My end result should be something like this but Total Views Weekly.
My sample non php code is:
<div id="chart_div" style="width: 100%; height: 500px;"></div>
<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(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Week', 'Signup'],
['2018/10/15', 0],
['2018/10/16', 0],
['2018/10/17', 0],
['2018/10/18', 0],
['2018/10/19', 4],
['2018/10/20', 4],
['Today', 227]
]);
var options = {
chart: {
title: 'Total Signup',
//subtitle: 'Sales, Expenses, and Profit: 2014-2017',
}
};
var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
</script>