View source
<?php
function google_chart_tools_example_menu() {
$items = array();
$items['reports/site-analytics'] = array(
'title' => 'Site Analytics',
'access arguments' => array(
'access content',
),
'page callback' => 'google_chart_tools_page',
);
return $items;
}
function google_chart_tools_page() {
$header = $nodes = $comments = $votes = array();
$from = strtotime('-1 month');
$to = time();
$i = 0;
while ($from <= $to) {
$header[$i] = date('d.m.y', strtotime("-{$i} day"));
$nodes[$i] = db_query("SELECT COUNT(*) FROM {node} WHERE FROM_UNIXTIME(created,'%d.%m.%y') = :dete", array(
':dete' => $header[$i],
))
->fetchField();
$comments[$i] = db_query("SELECT COUNT(*) FROM {comment} WHERE FROM_UNIXTIME(created,'%d.%m.%y') = :dete", array(
':dete' => $header[$i],
))
->fetchField();
$votes[$i] = module_exists('votingapi') ? db_query("SELECT COUNT(*) FROM {votingapi_vote} WHERE FROM_UNIXTIME(timestamp,'%d.%m.%y') = :dete", array(
':dete' => $header[$i],
))
->fetchField() : 0;
$users[$i] = db_query("SELECT COUNT(*) FROM {users} WHERE FROM_UNIXTIME(created,'%d.%m.%y') = :dete", array(
':dete' => $header[$i],
))
->fetchField();
$i++;
$from = strtotime("+1 day", $from);
}
$rows = array(
$nodes,
$comments,
$votes,
$users,
);
$columns = array(
'No. Of Nodes',
'No. Of Comments',
'No. Of Votes',
'No. Of Users',
);
$settings = array();
$settings['chart']['chartOne'] = array(
'header' => $header,
'rows' => $rows,
'columns' => $columns,
'chartType' => GOOGLE_CHART_TOOLS_DEFAULT_CHART,
'containerId' => 'line_chart',
'options' => array(
'curveType' => "function",
'forceIFrame' => FALSE,
'title' => 'Nodes / Comments / Votes / Users per day',
'width' => 800,
'height' => 400,
),
);
$tree = array(
array(
'Grandparent',
'<font color="red">Grandparent</font>',
'',
'Grandparent Tooltip',
'',
'',
),
array(
'Parent',
'',
'Grandparent',
'',
'border-color:green',
'border-color:red',
),
array(
'Child1',
'',
'Parent',
'',
'',
'',
),
array(
'Child2',
'',
'Parent',
'Child 2 Tooltip',
'',
'',
),
);
$settings['chart']['chartTwo'] = array(
'header' => 'Header',
'containerId' => 'org_chart',
'chartType' => 'OrgChart',
'rows' => $tree,
'options' => array(
'title' => 'Org Chart',
'allowHtml' => 'true',
'allowCollapse' => 'true',
),
);
draw_chart($settings);
return '<p>Example line chart:</p><div id="line_chart"></div><p>Example org chart:</p><div id="org_chart" class="org_chart"></div>';
}