-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_piechart.php
71 lines (67 loc) · 2.4 KB
/
example_piechart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
include_once(__DIR__.'/classes/class.nUberJTools.php');
$result = array(
0 => array(
'id' => 1,
'lesson' => 'Community Health Care',
'lesson_activity' => 'CHC.001',
'count(<50%)' => 7,
'count(Between 50-60%)' => 4,
'count(>60%)' => 9),
1 => array(
'id' => 2,
'lesson' => 'Community Health Care',
'lesson_activity' => 'CHC.002',
'count(<50%)' => 32,
'count(Between 50-60%)' => 11,
'count(>60%)' => 65),
2 => array(
'id' => 3,
'lesson' => 'Community Health Care',
'lesson_activity' => 'CHC.003',
'count(<50%)' => 44,
'count(Between 50-60%)' => 12,
'count(>60%)' => 76));
$Googlizer = nUberJTools::GoogleCharts();
$title = "My Trend Chart";
// Set options in general
$options['legend'] = 'none';
$options['is3D'] = 'true';
foreach($result as $i=> $row) {
// The incr setting allows for unique identifier when making multiple charts
$settings["incr"] = $i;
// Create a holder name for the javascript function
$settings['id'] = "trend".$settings["incr"];
// Create a title
$settings['title'] = "PieChart ".$i;
// Assign data for js function to use
$settings['data'] = array(
// Pie Chart needs a title row
"Title"=>$settings['title'],
// String required for key which shows as the
// title for the pie slice
"cond1"=>$row['count(<50%)'],
"cond2"=>$row['count(Between 50-60%)'],
"cond3"=>$row['count(>60%)']
);
// Returns the assembled js data arrays and the js function that displays chart
// Create the piechart
$Googlizer ->CreateChart($settings)
// This assembles the javascript data arrays and functions that create the charts
->jScripter()
// Build the html placeholders
->MakeContainer(array("w"=>500,"h"=>500,"unit"=>"px","wrap"=>"div"));
}
// This applies the javascript options
echo $Googlizer ->ChartOptions($options)
// This sets the kind of chart to display
->ChartKind(GoogleCharts::PIE)
// This writes everything to the page using the assemple data arrays and functions from the loop.
// The wrap option will write "<script>"
->CreateJavascript(array("wrap"=>true,"lib"=>true));
?>
<html>
<body>
<?php echo $Googlizer->Containers(); ?>
</body>
</html>