大家好,我是java1234_小鋒老師,最近寫了一套【NLP輿情分析】基于python微博輿情分析可視化系統(flask+pandas+echarts)視頻教程,持續更新中,計劃月底更新完,感謝支持。今天講解主頁-評論用戶時間占比環形餅狀圖實現
視頻在線地址:
2026版【NLP輿情分析】基于python微博輿情分析可視化系統(flask+pandas+echarts+爬蟲) 視頻教程 (火爆連載更新中..)_嗶哩嗶哩_bilibili
課程簡介:
?
本課程采用主流的Python技術棧實現,Mysql8數據庫,Flask后端,Pandas數據分析,前端可視化圖表采用echarts,以及requests庫,snowNLP進行情感分析,詞頻統計,包括大量的數據統計及分析技巧。
實現了,用戶登錄,注冊,爬取微博帖子和評論信息,進行了熱詞統計以及輿情分析,以及基于echarts實現了數據可視化,包括微博文章分析,微博IP分析,微博評論分析,微博輿情分析。最后也基于wordcloud庫實現了詞云圖,包括微博內容詞云圖,微博評論詞云圖,微博評論用戶詞云圖等功能。
主頁-評論用戶時間占比環形餅狀圖實現
首先commentDao實現獲取7天用戶評論量
def getCommentAmount():"""獲取7天用戶評論量:return:"""con = Nonetry:con = dbUtil.getCon()cursor = con.cursor()sql = "select DATE_FORMAT(created_at, '%Y-%m-%d') as commentDate,count(text_raw) as commentTotal from t_comment group by DATE_FORMAT(created_at, '%Y-%m-%d') order by commentDate desc limit 0,7"cursor.execute(sql)return cursor.fetchall()except Exception as e:print(e)con.rollback()return Nonefinally:dbUtil.closeCon(con)
page.py的home()方法里,調用commentDao獲取數據,然后轉發到主頁面
# 獲取評論數量(最近7天)commentData = []commentAmountList = commentDao.getCommentAmount()for comment in commentAmountList:commentData.append({'value': comment[1], 'name': comment[0]})
?return render_template('index.html',xAxis7ArticleData=xAxis7ArticleData,yAxis7ArticleData=yAxis7ArticleData,arcTypeData=arcTypeData,commentData=commentData)
index.html里 定義圖表對象,用得是餅狀圖,設置數據對象。
var chartDom = document.getElementById('commentUserZb');var myChart = echarts.init(chartDom);var option;
?option = {tooltip: {trigger: 'item'},legend: {top: '5%',left: 'center'},series: [{name: '評論用戶時間占比',type: 'pie',radius: ['40%', '70%'],avoidLabelOverlap: false,itemStyle: {borderRadius: 10,borderColor: '#fff',borderWidth: 2},label: {show: false,position: 'center'},emphasis: {label: {show: true,fontSize: 40,fontWeight: 'bold'}},labelLine: {show: false},data: {{ commentData | tojson }}}]};
?option && myChart.setOption(option);
運行系統: