document.addEventListener('DOMContentLoaded', function() { var chartDom = document.getElementById('r1'); var myChart = echarts.init(chartDom); var option; fetch('/barrage_sentiment') .then(response => response.json()) .then(data => { // 只加载前100条数据 data = data.slice(0, 250); var scatterData = data.map((item, index) => [index, item.sentiment]); option = { title: { text: '弹幕情感分析', left: 'center', top: 'bottom', textStyle: { color: '#FFFFFF', } }, tooltip: {}, xAxis: { type: 'category', data: data.map((item, index) => index), axisLabel: { show:false } }, yAxis: { type: 'value' }, series: [{ data: scatterData, type: 'scatter', itemStyle: { color: 'rgba(255, 0, 0, 0.8)' } }] }; myChart.setOption(option); }); });