index.html
12 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!doctype html>
<!-- Copyright (c) 2014 Google Inc. All rights reserved. -->
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>google-chart Demo</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../google-chart.html">
<style>
code {
color: #007000;
}
google-chart {
height: 300px;
width: 400px;
}
#selection-demo {
position: relative;
height: 300px;
}
#selection-chart {
float: left;
}
#selection-display {
display: inline-block;
position: relative;
top: 50%;
}
</style>
</head>
<body>
<p>A simple <code>google-chart</code> looks like this:</p>
<google-chart
cols='[{"label": "Data", "type": "string"},{"label": "Value", "type": "number"}]'
rows='[["Something", 1]]'>
</google-chart>
<p>Charts can be resized with CSS, but you'll need to call the <code>drawChart</code> method when the size changes.</p>
<p>Here's a basic responsive example using only CSS and JS. You could also use <code><iron-media-query></code>.</p>
<style>
/* Phone and tablet */
#resizing_chart {
height: 300px;
width: 400px;
}
/* Desktop */
@media screen and (min-width: 1024px) {
#resizing_chart {
width: 800px;
}
}
</style>
<script>
var media = window.matchMedia('(min-width: 1024px)');
media.addListener(function() {
document.getElementById('resizing_chart').drawChart();
});
</script>
<google-chart
id='resizing_chart'
type='column'
options='{"title": "Responsive chart",
"vAxis": {"minValue" : 0, "maxValue": 10}}'
cols='[{"label": "Data", "type": "string"},{"label": "Value", "type": "number"}]'
rows='[["Col1", 5.0],["Col2", 5.0],["Col3", 5.0]]'>
</google-chart>
<p>Here's a chart that changes data every 3 seconds:</p>
<google-chart
id='mutating_chart'
type='column'
options='{"title": "Random data",
"vAxis": {"minValue" : 0, "maxValue": 10},
"animation": {"duration": "1000"}}'
cols='[{"label": "Data", "type": "string"},{"label": "Value", "type": "number"}]'
rows='[["Col1", 5.0],["Col2", 5.0],["Col3", 5.0]]'>
</google-chart>
<script>
function getRandomValue() {
return Math.random() * 10;
}
window.setInterval(function() {
var chart = document.getElementById('mutating_chart');
chart.rows = [["Col1", getRandomValue()],
["Col2", getRandomValue()],
["Col3", getRandomValue()]];
}, 3000);
</script>
<p>Here's a pie chart with an area selection:</p>
<div id="selection-demo">
<google-chart
type="pie"
id="selection-chart"
options='{"title": "Distribution of days in 2001H1"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<div id="selection-display">
Selected row: <span id="selection-label">None</span>.
</div>
</div>
<script>
document.addEventListener('WebComponentsReady', function() {
var chart = document.querySelector('#selection-chart');
var label = document.querySelector('#selection-label');
chart.addEventListener('google-chart-render', function() {
chart.selection = [{row: 1, column: null}];
label.textContent = chart.selection[0].row;
});
document.addEventListener('google-chart-select', function(e) {
label.textContent =
chart.selection[0] ? chart.selection[0].row : 'None';
});
});
</script>
<p>Here's a chart defined using <code>data</code>, rather than <code>rows</code> and <code>cols</code>:</p>
<google-chart
type='column'
options='{"title": "Inventory"}'
data='[["Year", "Things", "Stuff"],
["2004", 1000, 400],
["2005", 1170, 460],
["2006", 660, 1120],
["2007", 1030, 540]]'>
</google-chart>
<p>And one with some pretty complicated styling, where the data is loaded from an external JSON resource using the <code>data</code> attribute:</p>
<google-chart
type='column'
options='{"title": "Bar height", "legend": "none"}'
data='chart-data.json'>
</google-chart>
<p>Website traffic data by country from an external JSON resource where the data is in raw DataTable format.</p>
<google-chart
type='column'
options='{"title": "Visitors by Country", "legend": "none"}'
data='country-data.json'>
</google-chart>
<h2>Chart gallery</h2>
<p>Here's an area chart:</p>
<google-chart
type='area'
options='{"title": "Days in a month"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a bar chart:</p>
<google-chart
type='bar'
options='{"title": "Days in a month"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a bubble chart:</p>
<google-chart
type='bubble'
options='{}'
data='[["ID", "Life Expectancy", "Fertility Rate", "Region", "Population"],
["CAN", 80.66, 1.67, "North America", 33739900],
["DEU", 79.84, 1.36, "Europe", 81902307],
["DNK", 78.6, 1.84, "Europe", 5523095],
["EGY", 72.73, 2.78, "Middle East", 79716203],
["GBR", 80.05, 2, "Europe", 61801570],
["IRN", 72.49, 1.7, "Middle East", 73137148],
["IRQ", 68.09, 4.77, "Middle East", 31090763],
["ISR", 81.55, 2.96, "Middle East", 7485600],
["RUS", 68.6, 1.54, "Europe", 141850000],
["USA", 78.09, 2.05, "North America", 307007000]]'>
</google-chart>
<p>Here's a candlestick chart:</p>
<google-chart
type='candlestick'
options='{"legend": "none"}'
data='[["Day", "low", "start", "end", "high"],
["Mon", 20, 28, 38, 45],
["Tue", 31, 38, 55, 66],
["Wed", 50, 55, 77, 80],
["Thu", 77, 77, 66, 50],
["Fri", 68, 66, 22, 15]]'>
</google-chart>
<p>Here's a column chart:</p>
<google-chart
type='column'
options='{"title": "Days in a month"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a combo chart:</p>
<google-chart
type='combo'
options='{"seriesType": "bars", "series": {"2": {"type": "line"}}}'
data='[["Day", "A", "B", "C"],
["Mon", 20, 45, 28],
["Tue", 31, 66, 38],
["Wed", 50, 80, 55],
["Thu", 77, 50, 77],
["Fri", 68, 15, 66]]'>
</google-chart>
<p>Here's a geo chart:</p>
<google-chart
type='geo'
data='[["Country", "Popularity"],
["Germany", 200],
["United States", 300],
["Brazil", 400],
["Canada", 500],
["France", 600],
["RU", 700]]'>
</google-chart>
<p>Here's a histogram:</p>
<google-chart
type='histogram'
options='{"title": "Days in a month", "legend": "none", "histogram": { "bucketSize": 1 }}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a line chart:</p>
<google-chart
id='line_chart'
type='line'
options='{"title": "Days in a month"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a pie chart:</p>
<google-chart
type='pie'
options='{"title": "Distribution of days in 2001H1"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a scatter chart:</p>
<google-chart
type='scatter'
options='{"legend": "none"}'
data='[["A", "B"],
[20, 45],
[31, 66],
[50, 80],
[77, 50],
[68, 15]]'>
</google-chart>
<p>Here's a stepped area chart:</p>
<google-chart
type='stepped-area'
options='{"title": "Days in a month"}'
cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}]'
rows='[["Jan", 31],["Feb", 28],["Mar", 31],["Apr", 30],["May", 31],["Jun", 30]]'>
</google-chart>
<p>Here's a table chart:</p>
<google-chart
type="table"
options='{"title": "Inventory"}'
data='[["Year", "Things", "Stuff"],
["2004", 1000, 400],
["2005", 1170, 460],
["2006", 660, 1120],
["2007", 1030, 540]]'>
</google-chart>
<p>Here are three gauges:</p>
<google-chart
type='gauge'
data='[["Label", "Value"],["Memory", 80],["CPU", 55],["Network", 68]]'
options='{"width": 400,
"height": 120,
"redFrom": 90,
"redTo": 100,
"yellowFrom":75,
"yellowTo": 90,
"minorTicks": 5}'>
</google-chart>
<p>Here are three gauges with random data that change every three seconds:</p>
<google-chart
id="mutating_gauge"
type="gauge"
data='[["Label", "Value"],["Memory", 80],["CPU", 55],["Network", 68]]'
options='{"width": 400,
"height": 120,
"redFrom": 90,
"redTo": 100,
"yellowFrom": 75,
"yellowTo": 90,
"minorTicks": 5}'>
</google-chart>
<script>
function getRandomGaugeValue(offset, factor) {
return offset + Math.round(factor * Math.random());
}
window.setInterval(function() {
var gauge = document.getElementById('mutating_gauge');
gauge.data = [["Label", "Value"],["Memory", getRandomGaugeValue(40, 60)],["CPU", getRandomGaugeValue(40, 60)],["Network", getRandomGaugeValue(60, 20)]];
}, 3000);
</script>
<p>Here's a treemap:</p>
<google-chart
type="treemap"
options='{"showScale": true, "maxPostDepth": 2}'
data='[["Location", "Parent", "Value"],
["Global", null, 0],
["America", "Global", 0],
["Europe", "Global", 0],
["Asia", "Global", 0],
["Australia", "Global", 0],
["Africa", "Global", 0],
["Brazil", "America", 11],
["USA", "America", 52],
["Mexico", "America", 24],
["Canada", "America", 16],
["France", "Europe", 42],
["Germany", "Europe", 31],
["Sweden", "Europe", 22],
["Italy", "Europe", 17],
["UK", "Europe", 21],
["China", "Asia", 36],
["Japan", "Asia", 20],
["India", "Asia", 40],
["Laos", "Asia", 4],
["Mongolia", "Asia", 1],
["Israel", "Asia", 12],
["Iran", "Asia", 18],
["Pakistan", "Asia", 11],
["Egypt", "Africa", 21],
["S. Africa", "Africa", 30],
["Sudan", "Africa", 12],
["Congo", "Africa", 10],
["Zaire", "Africa", 8]]'>
</google-chart>
<p>Here's an image of the line chart:</p>
<div id='line_chart_div'></div>
<script>
document.addEventListener('WebComponentsReady', function() {
var chart_div = document.querySelector('#line_chart_div');
var chart = document.querySelector('#line_chart');
chart.addEventListener('google-chart-render', function() {
chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
});
});
</script>
</body>
</html>