timeline图使用

学习测试做的一个产量统计图,多的不说了,上代码:

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()

结果图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pypup

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值