-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhistogram.js
116 lines (112 loc) · 2.36 KB
/
histogram.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
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js'
/**
* `histogram`
* A barchart visualisation
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class Histogram extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
.top{
margin-bottom: 20px;
}
.card {
border: 1px solid #f1f1f1;
height: 400px;
width: 400px;
border-radius: 5px;
padding: 20px;
box-shadow: 0px 0px 8px #888888;
background: white;
}
h1 {
font-family: Roboto, Arial, sans-serif;
font-weight: 100;
font-size: 24px;
margin: 0;
padding: 0;
color: #424242;
}
h2 {
font-family: Roboto, Arial, sans-serif;
font-weight: 600;
font-size: 14px;
margin: 0;
padding: 0;
color: #a1a1a1
}
</style>
<div class="card">
<div class="top">
<h1 class="title">[[title]]</h1>
<h2 class="subtitle">[[subtitle]]</h2>
</div>
<div class="mid">
<canvas class="myChart"></canvas>
</div>
<div class="bottom"></div>
</div>
`;
}
static get properties() {
return {
height: {
type: Number,
value: '200',
},
width: {
type: Number,
value: '400',
},
title: {
type: String,
value: 'This is a histogram',
},
subtitle: {
type: String,
value: 'A reusable visualisation component',
},
data: {
type: Array,
value: function() {
return [];
},
//observer: '_dataChanged'
}
};
}
ready() {
super.ready();
var ctx = this.shadowRoot.querySelector("canvas").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["1", "2", "3", "4", "5", "6"],
datasets: [{
data: [3, 6, 8, 9, 7, 4],
}]
},
options: {
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
}
}
window.customElements.define('vis-histogram', Histogram);