学习测试做的一个产量统计图,多的不说了,上代码:
import pymssql
from pyecharts.charts import Timeline, Bar
from pyecharts import options as opts
HOST = '***'
USER = '***'
PSW = '***'
DB = '****'
date_line = "exec [SCKB_jcxx] 'dateline'"
productline = "exec [SCKB_jcxx] 'productline'"
ALL = "exec [SCKB_jcxx] 'all'"
def connsql(sql):
conn = pymssql.connect(host=HOST, user=USER, password=PSW, database=DB, charset="utf8")
cur = conn.cursor()
cur.execute(sql)
# 执行sql语句
sql_list = cur.fetchall()
# 将语句执行结果赋值给sql_list
cur.close()
conn.close()
return sql_list
def crt_dh():
all_group = connsql(ALL)
timeline = [i[0] for i in all_group]
productlinename = [i[1] for i in all_group]
time_line = list(set(timeline))
product_line = list(set(productlinename))
time_line.sort(key=timeline.index)
product_line.sort(key=productlinename.index)
# 取列表中的日期出来,去重后赋值给time_line
tl = Timeline()
for itl in time_line:
output = [b[2] for b in all_group if b[0] == itl]
bar = (
Bar()
.add_xaxis(product_line)
.add_yaxis("排产量", [0 for _ in product_line])
.add_yaxis("实际量", output)
.set_global_opts(title_opts=opts.TitleOpts("{}日生产量".format(itl.strftime('%Y-%m-%d'))))
)
tl.add(bar, "{}日".format(itl.strftime('%Y-%m-%d')))
tl.render('zhuzhuangtu4.html')
if __name__ == '__main__':
crt_dh()
结果图: