/
exampleStackedBarchart.html
164 lines (139 loc) · 5.17 KB
/
exampleStackedBarchart.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>HEAVY.AI</title>
<meta charset="UTF-8">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
<style>
.title {
font-weight: bold;
text-align:center;
}
.heavyai {
position: relative;
top: 2px;
}
.search{
display: inline-block;
margin-top: 12px;
margin-left: 50px;
}
.data-count {
padding-right:20px;
}
.filter-count {
font-weight: bold;
color: #45B1E8;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header" style="margin-top:10px">
<img alt="Brand" src="images/favicon.png" height="30" width="30">
<span class="heavyai">HEAVY.AI Demo</span>
</div>
</div>
</nav>
<div class="col-xs-12">
<div class="title">Stacked Bar Chart</div>
<div class="stacked-bar-example"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="assets/app.bundle.js"></script>
<script>
var globalGeocoder = null;
function createCharts(crossFilter, con, tableName) {
var w = document.documentElement.clientWidth - 30;
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 150;
var timeChartMeasures = [
{
expression: "join_time",
agg_mode:"min",
name: "minimum"
},
{
expression: "join_time",
agg_mode:"max",
name: "maximum"}
]
crossFilter
.groupAll()
.reduce(timeChartMeasures)
.valuesAsync(true).then(function(timeChartBounds) {
var joinDimension = crossFilter.dimension(["join_time", "country"])
var joinGroup = joinDimension
.group()
.reduceCount()
var dcTimeChart = dc.barChart('.stacked-bar-example')
.width(w)
.height(h)
.elasticY(true)
.renderHorizontalGridLines(true)
.xAxisLabel('Join Time')
.yAxisLabel('Number of New Users')
.dimension(joinDimension)
.group(joinGroup)
.binParams({
timeBin: 'month',
binBounds: [timeChartBounds.minimum, timeChartBounds.maximum]
});
/* Pass in a series to enable stacking function */
dcTimeChart.series().group(crossFilter.dimension('country').group())
dcTimeChart.series().selected(['US','BR','ID','AR','TR'])
/* Set the x and y axis formatting with standard d3 functions */
dcTimeChart
.x(d3.time.scale.utc().domain([timeChartBounds.minimum, timeChartBounds.maximum]))
.yAxis().ticks(5);
dcTimeChart
.xAxis()
.scale(dcTimeChart.x())
.tickFormat(dc.utils.customTimeFormat)
.orient('top');
dc.renderAllAsync()
/*--------------------------RESIZE EVENT------------------------------*/
window.addEventListener("resize", _.debounce(reSizeAll, 500));
function reSizeAll(){
var w = document.documentElement.clientWidth - 30;
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 150;
dcTimeChart
.width(w)
.height(h)
dc.redrawAllAsync();
}
});
}
function init() {
// A connector-js instance is used for performing raw queries on a HeavyDB GPU database.
new DbCon()
.protocol("https")
.host("metis.mapd.com")
.port("443")
.dbName("mapd")
.user("mapd")
.password("HyperInteractive")
.connect(function(error, con) {
// Get a table from the database
var tableName = 'tweets_nov_feb';
// A CrossFilter instance is used for generating the raw query strings for your connector-js.
var crossFilter = crossfilter.crossfilter(con, tableName)
.then(function(cf) {
createCharts(cf, con, tableName)
})
// Pass instance of crossfilter into our CreateCharts.
;
});
}
document.addEventListener('DOMContentLoaded', init, false);
function mapApiLoaded() {
globalGeocoder = new google.maps.Geocoder();
geocoderObject.geocoder = globalGeocoder;
}
</script>
</body>
</html>