-
Notifications
You must be signed in to change notification settings - Fork 130
/
index.html
658 lines (552 loc) · 19.4 KB
/
index.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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!doctype html>
<!-- Copyright (c) 2014 Google LLC 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="https://unpkg.com/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<style>
code {
color: #007000;
}
google-chart {
height: 300px;
width: 400px;
}
</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>redraw</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>
<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>
<script type="module">
import '../google-chart.js';
var media = window.matchMedia('(min-width: 1024px)');
media.addListener(function() {
document.getElementById('resizing-chart').redraw();
});
</script>
<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 type="module">
import '../google-chart.js';
function getRandomValue() {
return Math.random() * 10;
}
var chart = document.getElementById('mutating-chart');
window.setInterval(function() {
chart.rows = [["Col1", getRandomValue()],
["Col2", getRandomValue()],
["Col3", getRandomValue()]];
}, 3000);
</script>
<p>Here's a pie chart with an area selection:</p>
<style>
#selection-demo {
position: relative;
height: 300px;
}
#selection-chart {
float: left;
}
#selection-display {
display: inline-block;
position: relative;
top: 50%;
}
</style>
<div id="selection-demo">
<google-chart
id="selection-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] ]'
selection='[{"row": 1}]'>
</google-chart>
<div id="selection-display">
Selected row: <span id="selection-label">None</span>.
</div>
</div>
<script type="module">
import '../google-chart.js';
var chart = document.getElementById('selection-chart');
var label = document.getElementById('selection-label');
label.textContent = chart.selection[0].row;
chart.addEventListener('google-chart-select', function(e) {
var newSelection = e.detail.chart.getSelection()[0]; // From the event details
label.textContent = newSelection ? newSelection.row : 'None';
});
chart.addEventListener('selection-changed', function(e) {
var newSelection = e.detail.value[0]; // From the event details
label.textContent = newSelection ? newSelection.row : 'None';
});
</script>
<p>Here's a pie chart listening for `onmouseover`:</p>
<style>
#mouseover-demo {
position: relative;
height: 300px;
}
#mouseover-chart {
float: left;
}
#mouseover-display {
display: inline-block;
position: relative;
top: 50%;
}
</style>
<div id="mouseover-demo">
<google-chart
id="mouseover-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] ]'
events='["onmouseover"]'>
</google-chart>
<div id="mouseover-display">
Moused over row: <span id="mouseover-label">None</span>.
</div>
</div>
<script type="module">
import '../google-chart.js';
var chart = document.getElementById('mouseover-chart');
var label = document.getElementById('mouseover-label');
chart.addEventListener('google-chart-onmouseover', function(e) {
label.textContent = e.detail.data.row;
});
</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>And here is the material bar chart:</p>
<google-chart
type="md-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"
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 material line chart:</p>
<google-chart
id="line-chart-md"
type="md-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 organization chart:</p>
<google-chart
id="org-chart",
type="org",
options='{"allowHtml": "true"}'
cols='[{"label": "Name", "type": "string"},{"label":"Manager", "type":"string"},{"label":"ToolTip", "type":"string"}]'
rows='[[{"v":"Mike", "f":"Mike<div style=\"color:red; font-style:italic\">President</div>"},
"", "The President"],
[{"v":"Jim", "f":"Jim<div style=\"color:red; font-style:italic\">Vice President</div>"},
"Mike", "VP"],
["Alice", "Mike", ""],
["Bob", "Jim", "Bob Sponge"],
["Carol", "Bob", ""]]'>
</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 sankey diagram:</p>
<google-chart
type="sankey"
cols='[{"label": "From", "type": "string"},
{"label": "To", "type": "string"},
{"label": "Weight", "type": "number"}]'
rows='[[ "A", "X", 5 ],
[ "A", "Y", 7 ],
[ "A", "Z", 6 ],
[ "B", "X", 2 ],
[ "B", "Y", 9 ],
[ "B", "Z", 4 ]]'>
</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 material scatter chart:</p>
<google-chart
type="md-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", "page": "enable", "pageSize": 4}'
data='[["Year", "Things", "Stuff"],
["2004", 1000, 400],
["2005", 1170, 460],
["2006", 660, 1120],
["2007", 1030, 540],
["2008", 1000, 400],
["2009", 1170, 460],
["2010", 660, 1120],
["2011", 1030, 540]]'></google-chart>
<p>Here's a timeline chart:</p>
<google-chart id="timeline" type="timeline"></google-chart>
<script type="module">
import '../google-chart.js';
import {dataTable} from '../loader.js';
const chart = document.getElementById('timeline');
dataTable([
['Name', 'Start', 'End'],
['Washington', new Date(1789, 3, 30), new Date(1797, 2, 4)],
['Adams', new Date(1797, 2, 4), new Date(1801, 2, 4)],
['Jefferson', new Date(1801, 2, 4), new Date(1809, 2, 4)]
]).then((dataTable) => {
chart.data = dataTable;
});
</script>
<p>Here's a wordtree:</p>
<google-chart
type="wordtree"
data='[["Phrases"],
["cats are better than dogs"],
["cats eat kibble"],
["cats are better than hamsters"],
["cats are awesome"],
["cats are people too"],
["cats eat mice"],
["cats meowing"],
["cats in the cradle"],
["cats eat mice"],
["cats in the cradle lyrics"],
["cats eat kibble"],
["cats for adoption"],
["cats are family"],
["cats eat mice"],
["cats are better than kittens"],
["cats are evil"],
["cats are weird"],
["cats eat mice"]
]'></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 type="module">
import '../google-chart.js';
function getRandomGaugeValue(offset, factor) {
return offset + Math.round(factor * Math.random());
}
var gauge = document.getElementById('mutating-gauge');
window.setInterval(function() {
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 a Gantt chart:</p>
<google-chart id="gantt-chart" type="gantt"></google-chart>
<script type="module">
import '../google-chart.js';
import {dataTable} from '../loader.js';
const chart = document.getElementById('gantt-chart');
dataTable().then((data) => {
// See https://developers.google.com/chart/interactive/docs/gallery/ganttchart
function daysToMilliseconds(days) {
return days * 24 * 60 * 60 * 1000;
}
data.addColumn('string', 'Task ID');
data.addColumn('string', 'Task Name');
data.addColumn('date', 'Start Date');
data.addColumn('date', 'End Date');
data.addColumn('number', 'Duration');
data.addColumn('number', 'Percent Complete');
data.addColumn('string', 'Dependencies');
data.addRows([
['Research', 'Find sources',
new Date(2015, 0, 1), new Date(2015, 0, 5), null, 100, null],
['Write', 'Write paper',
null, new Date(2015, 0, 9), daysToMilliseconds(3), 25, 'Research,Outline'],
['Cite', 'Create bibliography',
null, new Date(2015, 0, 7), daysToMilliseconds(1), 20, 'Research'],
['Complete', 'Hand in paper',
null, new Date(2015, 0, 10), daysToMilliseconds(1), 0, 'Cite,Write'],
['Outline', 'Outline paper',
null, new Date(2015, 0, 6), daysToMilliseconds(1), 100, 'Research']
]);
chart.data = data;
});
</script>
<p>Here is a chart using a DataTable as its source:</p>
<google-chart
id="source-datatable"
type="bar">
</google-chart>
<script type="module">
import '../google-chart.js';
import {dataTable} from '../loader.js';
const chart = document.getElementById('source-datatable');
dataTable([
['Label', 'Value'],
['Memory', 10],
['CPU', 12],
['Network', 14]
]).then((dataTable) => {
chart.data = dataTable;
});
</script>
<p>Here is a chart using a filtered DataView as its source:</p>
<google-chart
id="source-dataview"
type="bar">
</google-chart>
<p>DataViews can be altered, but you'll need to call the <code>redraw</code> method afterward.</p>
<script type="module">
import '../google-chart.js';
import {dataTable} from '../loader.js';
const chart = document.getElementById('source-dataview');
dataTable([
['Label', 'Value'],
['Memory', 10],
['CPU', 12],
['Network', 14]
]).then((dataTable) => {
chart.view = new google.visualization.DataView(dataTable);
const setRandomRow = () => {
const rowCount = dataTable.getNumberOfRows();
const row = Math.floor(Math.random() * rowCount);
const row2 = (row + 1) % rowCount;
chart.view.setRows([row, row2]);
chart.redraw();
};
setInterval(setRandomRow, 3000);
});
</script>
<p>Here's an image of the line chart:</p>
<img id="line-chart-img">
<script type="module">
import '../google-chart.js';
var chart = document.getElementById('line-chart');
var img = document.getElementById('line-chart-img');
chart.addEventListener('google-chart-ready', function() {
img.src = chart.imageURI;
});
</script>
</body>
</html>