-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboardcharts.php
171 lines (147 loc) · 5.94 KB
/
dashboardcharts.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
<?php
require('phpcassa/lib/autoload.php');
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
$servers = array("10.5.14.58:9160");
$pool = new ConnectionPool("client_logging", $servers);
$column_family = new ColumnFamily($pool, 'dashboard_loc');
$rows = $column_family->get_range("", "", 100, NULL);
?>
google.load('visualization', '1.0', {'packages':['corechart', 'geochart', 'table']});
google.setOnLoadCallback(drawCombo);
function drawCombo() {
drawPieChart();
drawGeoMap();
drawDataTable();
}
function drawPieChart() {
// Create the data table.
<?php
$type2NumArray = array();
$city2NumArray = array();
foreach($rows as $key => $columns) {
foreach($columns as $k => $cs) {
if (array_key_exists($key, $offerTypeArray)) {
$type2NumArray[$key] = (int)$type2NumArray[$key] + (int)$cs;
}
else {
$type2NumArray[$key] = (int)$cs;
}
if (array_key_exists($k, $city2NumArray)) {
$city2NumArray[$k] = (int)$city2NumArray[$k] + (int)$cs;
}
else {
$city2NumArray[$k] = (int)$cs;
}
}
}
?>
var type2NumData = google.visualization.arrayToDataTable([
['Offer Type', 'Number'],
<?php
foreach($type2NumArray as $key => $value) {
print "['$key', $value],";
}
?>
]);
// Set chart options
var type2NumOptions = {
'legend.position' : 'right',
'title' : 'Distribution By Offer Type',
'is3D' : true,
'width' : 800,
'height' : 500
}
// Instantiate and draw our chart, passing in some options.
var type2NumChart = new google.visualization.PieChart(document.getElementById('chartByType_div'));
function selectHandler() {
var selectedItem = type2NumChart.getSelection()[0];
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
alert(' ' + topping);
}
}
google.visualization.events.addListener(type2NumChart, 'select', selectHandler);
type2NumChart.draw(type2NumData, type2NumOptions);
// city2Num pie chart
var city2NumData = google.visualization.arrayToDataTable([
['City', 'Number'],
<?php
foreach($city2NumArray as $key => $value) {
print "['$key', $value],";
}
?>
]);
// Set chart options
var city2NumOptions = {
'legend.position' : 'right',
'title' : 'Distribution By City',
'is3D' : true,
'width' : 800,
'height' : 500
}
// Instantiate and draw our chart, passing in some options.
var city2NumChart = new google.visualization.PieChart(document.getElementById('chartByCity_div'));
function selectHandler() {
var selectedItem = type2NumChart.getSelection()[0];
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
alert(' ' + topping);
}
}
google.visualization.events.addListener(city2NumChart, 'select', selectHandler);
city2NumChart.draw(city2NumData, city2NumOptions);
}
function drawGeoMap() {
var geoData = google.visualization.arrayToDataTable([
['City', 'Offer Numbers'],
<?php
foreach($rows as $key => $columns) {
foreach($columns as $k => $cs) {
print "['$k', $cs],";
}
}
print "['Seattle', 100]";
?>
]);
var options = {
region: 'US',
displayMode: 'markers',
colorAxis: {colors: ['green', 'blue']}
};
var geoMap = new google.visualization.GeoChart(document.getElementById('map_div'));
geoMap.draw(geoData, options);
}
function drawDataTable() {
// data table
var tableData = google.visualization.arrayToDataTable([
['Offer Path', 'City', 'Number'],
<?php
foreach($rows as $key => $columns) {
foreach($columns as $k => $cs) {
print "['$key', '$k' , '$cs'],";
}
}
print "['', '', '']";
?>
]);
var dataTable = new google.visualization.Table(document.getElementById('table_div'));
dataTable.draw(tableData, null);
}
</script>
</head>
<body>
<div id="chartByType_div"></div>
<div id="chartByCity_div"></div>
<div id="map_div"></div>
<div id="table_div"></div>
</body>
</html>