根據csv製作多列數據柱形圖表並生成html

數據表收錄已經過千萬了,爲了分表,先用sql調出數據然後渲染

csv如下:

在這裏插入圖片描述

代碼如下:

# -*- coding: utf-8 -*-
# pip install pyecharts

import pandas as pd
import numpy as np
from pyecharts import Bar

df = pd.read_csv("monthbybdtype.csv")


print(df.head())
# xdata=df['日期']
# ydata=df['總數']


xdata=[]
type1=[]
type2=[]
type3=[]
type4=[]
for i in df.values:
    if i[1]>='2019-10':
        if i[1] not in xdata:
            xdata.append(i[1])
        if i[2] == 1:
            type1.append(i[0])
        elif i[2] == 2:
            type2.append(i[0])
        elif i[2] == 3:
            type3.append(i[0])
        elif i[2] == 4:
            type4.append(i[0])
        else:
            type1.append(0)
            type3.append(0)
            type4.append(0)

bar = Bar("統計", "2020-03-11", title_pos='right', title_color='blue', width=900, height=500,background_color='white')
bar.add("test1", xdata, type1,is_label_show=True,mark_line=["average"], legend_text_color='black')
bar.add("test4", xdata, type4,is_label_show=True,mark_line=["average"])
bar.add("test3", xdata, type3,is_label_show=True,mark_line=["average"])
# bar.show_config()
bar.render('aa.html')

width=900, height=500 可以直接在bar裏面配置;由於最新版本和老版本用法區別,import Bar 失敗 版本不對,執行pip install pyecharts==0.1.9.4即可

效果:

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章