-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3.js
171 lines (160 loc) · 5.4 KB
/
example3.js
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
var labelType, useGradients, nativeTextSupport, animate;
(function () {
var ua = navigator.userAgent,
iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
typeOfCanvas = typeof HTMLCanvasElement,
nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
textSupport = nativeCanvasSupport && (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
//I'm setting this based on the fact that ExCanvas provides text support for IE
//and that as of today iPhone/iPad current text support is lame
labelType = (!nativeCanvasSupport || (textSupport && !iStuff)) ? 'Native' : 'HTML';
nativeTextSupport = labelType == 'Native';
useGradients = nativeCanvasSupport;
animate = !(iStuff || !nativeCanvasSupport);
})();
var Log = {
elem: false,
write: function (text) {
if (!this.elem) this.elem = document.getElementById('log');
this.elem.innerHTML = text;
this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px';
}
};
var json;
var json2;
var mydata;
function init() {
//init data
$.ajax({
url: 'ajax/_categ.php',
type: 'GET',
dataType: 'jsonp',
dataCharset: 'jsonp',
success: function (data) {
var json = eval(data[0]);
/*
//init BarChart
var barChart = new $jit.AreaChart({
//id of the visualization container
injectInto: 'infovis',
//add animations
animate: true,
//separation offsets
Margin: {
top: 5,
left: 5,
right: 5,
bottom: 5
},
labelOffset: 10,
//whether to display sums
showAggregates: true,
//whether to display labels at all
showLabels: true,
//could also be 'stacked'
type:'stacked',
//label styling
Label: {
type: labelType, //can be 'Native' or 'HTML'
size: 13,
family: 'Arial',
color: 'white'
},
//enable tips
Tips: {
enable: true,
onShow: function(tip, elem) {
tip.innerHTML = "<b>" + elem.name + "</b>: " + elem.value;
}
},
//add left and right click handlers
filterOnClick: true,
restoreOnRightClick:true
});
barChart.loadJSON(json);
*/
var barChart = new $jit.BarChart({
//id of the visualization container
injectInto: 'infovis',
//whether to add animations
animate: true,
//horizontal or vertical barcharts
orientation: 'vertical',
//bars separation
barsOffset: 20,
//visualization offset
Margin: {
top: 5,
left: 5,
right: 5,
bottom: 5
},
//labels offset position
labelOffset: 5,
//bars style
type:'stacked',
//whether to show the aggregation of the values
showAggregates: true,
//whether to show the labels for the bars
showLabels: true,
//labels style
Label: {
type: labelType, //Native or HTML
size: 13,
family: 'Arial',
color: 'white'
},
//add tooltips
Tips: {
enable: true,
onShow: function (tip, elem) {
tip.innerHTML = "<b>" + elem.name + "</b>: " + elem.value;
}
}
});
//load JSON data.
barChart.loadJSON(json);
//end
var list = $jit.id('id-list'),
button = $jit.id('update'),
button2 = $jit.id('update2'),
orn = $jit.id('switch-orientation');
//update json on click 'Update Data'
$jit.util.addEvent(button, 'click', function () {
var util = $jit.util;
if (util.hasClass(button, 'gray')) return;
util.removeClass(button, 'white');
util.addClass(button, 'gray');
util.removeClass(button2, 'gray');
util.addClass(button2, 'white');
barChart.updateJSON(json2);
});
$jit.util.addEvent(button2, 'click', function () {
var util = $jit.util;
if (util.hasClass(button2, 'gray')) return;
util.removeClass(button2, 'white');
util.addClass(button2, 'gray');
util.removeClass(button, 'gray');
util.addClass(button, 'white');
barChart.updateJSON(json);
});
//dynamically add legend to list
var legend = barChart.getLegend(),
listItems = [];
for (var name in legend) {
listItems.push('<div class=\'query-color\' style=\'background-color:' + legend[name] + '\'> </div>' + name);
}
list.innerHTML = '<li>' + listItems.join('</li><li>') + '</li>';
}
});
$.ajax({
url: 'ajax/_revenue.php',
type: 'GET',
dataType: 'jsonp',
dataCharset: 'jsonp',
success: function (data) {
//console.log(data[0]);
json2 = data[0];
}
});
}