function _charts_system_generate in Charts 7
Same name and namespace in other branches
- 6 charts_system/charts_system.inc \_charts_system_generate()
Generate some charts using a pre defined method.
Parameters
$title: String. The chart title
$sql: String. The SQL statement to be executed
$callback: String (optional). When a string is given, use it as the parser of the results from SQL. Its important when the results are coded in to DB to ocupy less space, and should be decoded.
Return value
String. The HTML chart when all data is fine or a blank string
1 call to _charts_system_generate()
- _charts_system_charts in charts_system/
charts_system.inc - Chart reports page
File
- charts_system/
charts_system.inc, line 101 - @author Bruno Massa http://drupal.org/user/67164 @author TJ (based on his Chart module)
Code
function _charts_system_generate($title, $sql, $callback = NULL) {
$results = db_query($sql);
while ($result = db_fetch_array($results)) {
if (!empty($callback)) {
$result['name'] = $callback($result['name']);
}
$data[] = array(
'#value' => $result['count'],
'#label' => $result['name'] . ': ' . $result['count'],
);
}
if (!empty($data)) {
$chart = array();
$chart[0] = $data;
$chart['#title'] = $title;
$chart['#type'] = 'pie2D';
return charts_chart($chart);
}
return '';
}