2019-03-05 01:04:20 +09:00
|
|
|
import CalHeatMap from 'cal-heatmap';
|
|
|
|
import Chart from 'chart.js';
|
|
|
|
|
|
|
|
function createLineGraph(id, labels, data) {
|
|
|
|
const context = document.getElementById(id).getContext('2d');
|
|
|
|
new Chart(context, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
|
|
|
data: data,
|
|
|
|
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
|
|
|
borderColor: 'rgba(255, 99, 132, 1)',
|
|
|
|
borderWidth: 1
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
elements: {
|
|
|
|
line: {
|
|
|
|
tension: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBarGraph(id, labels, data) {
|
|
|
|
const context = document.getElementById(id).getContext('2d');
|
|
|
|
new Chart(context, {
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
|
|
|
data: data,
|
|
|
|
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
|
|
|
borderColor: 'rgba(255, 99, 132, 1)',
|
|
|
|
borderWidth: 1
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-05 01:08:17 +09:00
|
|
|
const graphData = JSON.parse(document.getElementById('graph-data').textContent);
|
2019-03-05 01:04:20 +09:00
|
|
|
|
|
|
|
new CalHeatMap().init({
|
|
|
|
itemSelector: '#cal-heatmap',
|
|
|
|
domain: 'month',
|
|
|
|
subDomain: 'day',
|
|
|
|
domainLabelFormat: '%Y/%m',
|
|
|
|
weekStartOnMonday: false,
|
|
|
|
start: new Date().setMonth(new Date().getMonth() - 9),
|
|
|
|
range: 10,
|
2019-03-05 01:08:17 +09:00
|
|
|
data: graphData.dailySum,
|
2019-03-05 01:04:20 +09:00
|
|
|
legend: [1, 2, 3, 4]
|
|
|
|
});
|
|
|
|
|
2019-03-05 01:08:17 +09:00
|
|
|
createLineGraph('monthly-graph', graphData.monthlyKey, graphData.monthlySum);
|
|
|
|
createLineGraph('yearly-graph', graphData.yearlyKey, graphData.yearlySum);
|
|
|
|
createBarGraph('hourly-graph', graphData.hourlyKey, graphData.hourlySum);
|
|
|
|
createBarGraph('dow-graph', ['日', '月', '火', '水', '木', '金', '土'], graphData.dowSum);
|