-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
54 lines (46 loc) · 1.13 KB
/
table.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
// register
Chart.visualizations['table'] = {
className: 'Table',
create: function(chart) {
return new Table(chart);
}
};
var Table = function(chart) {
var that = this;
this.chart = chart;
};
Table.prototype = {
render: function() {
$('#chart').html(this.renderCollection(this.chart.collection));
},
renderItem: function(c, i) {
var that = this;
str = '<tr>';
c.all("properties").eachKey(function(key, attr) {
if (i.type(key) === 'collection') {
str += '<td>'+that.renderCollection(i.first(key))+'</td>';
} else {
str += '<td>'
i.values(key).each(function(index, v) {
str += v+'<br/>';
});
str += '</td>'
}
});
str += '</tr>';
return str;
},
renderCollection: function(c) {
var that = this;
str = '<table><thead><tr>';
c.all("properties").each(function(index, p) {
str += '<th>'+p.name+'</th>';
});
str += '</tr></thead><tbody>';
c.all("items").each(function(index, item) {
str += that.renderItem(c, item);
});
str += '</tbody></table>';
return str;
}
};