import * as echarts from 'echarts';
const hours = [
'12am', '1am', '2am', '3am', '4am', '5am', '6am',
'7am', '8am', '9am', '10am', '11am',
'12pm', '1pm', '2pm', '3pm', '4pm', '5pm',
'6pm', '7pm', '8pm', '9pm', '10pm', '11pm'
];
const days = [
'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Sunday'
];
// Generate sample data: [day_index, hour_index, value]
const data = [];
for (let i = 0; i < 7; i++) {
for (let j = 0; j < 24; j++) {
data.push([i, j, Math.floor(Math.random() * 100)]);
}
}
const option = {
title: {
text: 'Weekly Activity Heatmap'
},
tooltip: {
position: 'top',
formatter: function (params) {
return `${days[params.value[0]]}<br/>${hours[params.value[1]]}: ${params.value[2]}`;
}
},
grid: {
height: '50%',
top: '10%'
},
xAxis: {
type: 'category',
data: days,
splitArea: {
show: true
}
},
yAxis: {
type: 'category',
data: hours,
splitArea: {
show: true
}
},
visualMap: {
min: 0,
max: 100,
calculable: true,
orient: 'horizontal',
left: 'center',
bottom: '15%',
inRange: {
color: ['#313695', '#4575b4', '#74add1', '#abd9e9',
'#e0f3f8', '#ffffbf', '#fee090', '#fdae61',
'#f46d43', '#d73027', '#a50026']
}
},
series: [
{
name: 'Activity',
type: 'heatmap',
data: data,
label: {
show: false
},
itemStyle: {
borderRadius: 4
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
const chart = echarts.init(document.getElementById('main'));
chart.setOption(option);