这是我在mysql提取出的数据
ec_right2.js
var ec_right2 = echarts.init(document.getElementById('r2'), "dark");
// var ddd = [{'name': '肺炎', 'value': '12734670'}, {'name': '实时', 'value': '12734670'},
// {'name': '新型', 'value': '12734670'}]
var ec_right2_option = {
// backgroundColor: '#515151',
title: {
text: "百度疫情症状热搜",
textStyle: {
color: 'white',
},
left: 'left'
},
tooltip: {
show: false
},
series: [{
type: 'wordCloud',
// drawOutOfBound:true,
gridSize: 1,
sizeRange: [12, 55],
rotationRange: [-45, 0, 45, 90],
// maskImage: maskImage,
textStyle: {
normal: {
color: function () {
return 'rgb(' +
Math.round(Math.random() * 255) +
', ' + Math.round(Math.random() * 255) +
', ' + Math.round(Math.random() * 255) + ')'
}
}
},
// left: 'center',
// top: 'center',
// // width: '96%',
// // height: '100%',
right: null,
bottom: null,
// width: 300,
// height: 200,
// top: 20,
data: []
}]
}
ec_right2.setOption(ec_right2_option);
utils.py
def get_r2_data():
"""
:return: 返回最近的30条热搜
"""
sql = 'select content from hotsearch order by id desc limit 30'
res = query(sql) #格式 (('民警抗疫一线奋战16天牺牲 1037364',), ('四川再派两批医疗队 1537382',)
return res
app.py
@app.route("/r2")
def get_r2_data():
data = utils.get_r2_data() #格式 (('民警抗疫一线奋战16天牺牲1037364',), ('四川再派两批医疗队1537382',)
hot = []
for i in data:
ks = extract_tags(i) # 使用jieba 提取关键字
for j in ks:
hot.append(j)
return jsonify({"content": hot})
controller.js
function get_r2_data() {
$.ajax({
url: "/r2",
success: function (data) {
ec_right2_option.series[0].data=data.hot;
ec_right2.setOption(ec_right2_option);
}
})
}
get_r2_data()
可以看看前端控制台有没有报错,确定前端的组件加载没有问题。在确认没有问题的基础上,可以使用官网的代码跑一下,用排除法大概可以找出来哪里有问题。