forked from amiechen/codrops-oasis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.js
93 lines (87 loc) · 1.79 KB
/
stats.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
function getWeeksArray() {
var weekArray = [];
for (var i = 0; i < 30; i++) {
weekArray.push("3/" + i);
}
return weekArray;
}
function getGeneratedLineData(numbers) {
return {
labels: getWeeksArray(),
datasets: [
{
borderColor: "rgba(174,155,255,0.67)",
pointColor: "#AE9BFF",
data: numbers,
pointRadius: 4,
borderWidth: 1,
pointBackgroundColor: "#C0B2FC"
}
]
};
}
function getGeneratedBarData(numbers) {
var labels = getWeeksArray();
return {
labels: getWeeksArray(),
datasets: [
{
labels: labels,
backgroundColor: "rgba(174,155,255,0.67)",
data: numbers
}
]
};
}
function randomArray(length, max) {
return Array.apply(null, Array(length)).map(function() {
return Math.round(Math.random() * max);
});
}
for (var i = 0; i < 6; i++) {
var ctx = document.getElementById("stats-" + i).getContext("2d");
var type, dataType;
if (i !== 1 && i !== 4) {
type = "line";
dataType = getGeneratedLineData(randomArray(30, 1000));
} else {
type = "bar";
dataType = getGeneratedBarData(randomArray(30, 1000));
}
new Chart(ctx, {
type: type,
data: dataType,
scaleShowVerticalLines: false,
scaleGridLineColor: "black",
options: {
responsive: true,
maintainAspectRatio: false,
elements: {
line: {
tension: 0
}
},
legend: {
display: false
},
scales: {
yAxes: [
{
ticks: {
fontColor: "#444363",
fontSize: 12
}
}
],
xAxes: [
{
ticks: {
fontColor: "#444363",
fontSize: 12
}
}
]
}
}
});
}