-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMMM-Chart.js
46 lines (36 loc) · 1.1 KB
/
MMM-Chart.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
/* global Chart Log Module */
/* MagicMirror²
* Module: MMM-Chart
*
* By Evghenii Marinescu https://github.com/evghenix/
* MIT Licensed.
*/
Module.register("MMM-Chart", {
defaults: {
width : 200,
height : 200,
chartConfig : {}
},
getScripts () {
return [`modules/${this.name}/node_modules/chart.js/dist/chart.umd.js`];
},
start () {
Log.info(`Starting module: ${this.name}`);
},
getDom () {
// Create wrapper element
const wrapperEl = document.createElement("div");
wrapperEl.setAttribute("style", "position: relative; display: inline-block;");
// Create chart canvas
const chartEl = document.createElement("canvas");
// Init chart.js
this.chart = new Chart(chartEl.getContext("2d"), this.config.chartConfig);
// Set the size
chartEl.width = this.config.width;
chartEl.height = this.config.height;
chartEl.setAttribute("style", "display: block;");
// Append chart
wrapperEl.appendChild(chartEl);
return wrapperEl;
}
});