You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.8 KiB

fetch('/data')
.then(response => response.json())
.then(data => {
let clusterData = {};
data.forEach(item => {
if (!clusterData[item.cluster]) {
clusterData[item.cluster] = [];
}
clusterData[item.cluster].push(item.barrage);
});
let seriesData = [];
for (let cluster in clusterData) {
seriesData.push({
name: `Cluster ${cluster}`,
type: 'bar',
data: clusterData[cluster].map((item, index) => ({ value: item.length, name: `弹幕 ${index + 1}` }))
});
}
let chart = echarts.init(document.getElementById('l1'));
let option = {
title: {
text: '弹幕聚类分析',
left:'center',
top: 'bottom',
textStyle: {
color: '#ffffff'
}
},
tooltip: {},
legend: {
data: seriesData.map(item => item.name),
textStyle: {
color: '#ffffff'
}
},
xAxis: {
data: seriesData[0].data.map(item => item.name),
axisLabel: {
show: false,
}
},
yAxis: {},
series: seriesData
};
chart.setOption(option);
});