BI报表项目:Echarts专题分析报表

时间:2024-10-14 07:17:01

BI报表项目:Echarts专题分析报表

项目背景:
公司不定期召开专题会议,就公司关键业务的运营指标进行分析讨论,以便及时发现问题并制定解决方案。

数据来源:
由相关销售部门提交的各直营店、授权专卖店销售数据,清洗后存入MySQL数据库。截取2015年-2018年的订单记录。
点击下面图片可显示高清原图:
在这里插入图片描述

1、各季度销售对比
使用横向柱状图(Bar)展示各年度的销售额,同时按季度堆叠,清晰的展示每年各个季度的销售对比,并且可以任意选择某个季度方便进行逐一对比。
点击下面图片可显示高清原图:
在这里插入图片描述

2、各城市销售额及利润分析
使用地理坐标系图表(Geo)直观的展示各城市销售额,越大的点表示销售额越高,同时加入利润的视觉映射,展示各城市带来的利润额。针对销售额及利润率超过阈值的城市,增加涟漪特效,突出显示当前业务的核心城市。
点击下面图片可显示高清原图:
在这里插入图片描述

3、各品类销售额对比
以月为单位,展现3个产品类别的销售额数据,使用柱状图(Bar)展示,为方便切换年份,加入时间线(Timeline)。也可以任意选择或隐藏每个品类,逐一进行分析。
点击下面图片可显示高清原图:
在这里插入图片描述

4、区域销售走势
自2015年以来,每天的销售走势,按区域做堆积面积图(Line,stack,area),直观的展示各大区销售走势。可以通过区域缩放控件(DataZoom)方便的选择某个时间段,也可以通过图例控件选择或隐藏某个大区。
点击下面图片可显示高清原图:
在这里插入图片描述

5、年度区域销售占比
直观的展示各年度各区域的销售额占比,可以选择或隐藏某个区域,逐一对比。
点击下面图片可显示高清原图:
在这里插入图片描述

附:Echarts代码

引入模块:

import numpy as np
import pandas as pd
import pymysql
import pyecharts
from pyecharts.charts import Bar,BMap,Line,Pie,Timeline,Map,Geo,Graph
from pyecharts import options as opts
from pyecharts.globals import ThemeType,GeoType
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1、各季度销售对比

横向堆叠柱状图:

bar_smt2 = Bar(init_opts=opts.InitOpts(width="800px",height="260px",theme=ThemeType.DARK))
bar_smt2.add_xaxis(x_year)
bar_smt2.add_yaxis("第1季度",y_Q1,stack=True)
bar_smt2.add_yaxis("第2季度",y_Q2,stack=True)
bar_smt2.add_yaxis("第3季度",y_Q2,stack=True)
bar_smt2.add_yaxis("第4季度",y_Q4,stack=True)
bar_smt2.reversal_axis()
bar_smt2.set_global_opts(legend_opts=opts.LegendOpts(pos_top="10px"),
                         title_opts=opts.TitleOpts(title="季度销售对比",pos_top="10px",pos_left="30px"))
bar_smt2.set_series_opts(label_opts=opts.LabelOpts(position="inside"))
bar_smt2.render_notebook()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2、各城市销售额及利润分析

地理坐标系:

geo1 = Geo(init_opts=opts.InitOpts(width="800px",height="500px",theme=ThemeType.DARK))
geo1.add_schema(maptype="china",is_roam=False)
for i in range(len(l_cs)):
    if l_cp_p[i][1]>10 and l_cs[i][1]>200000:   # 利润率超过10%并且销售额超过20万的地区使用涟漪散点
        geo1.add("",[l_cp[i]],type_="effectScatter",symbol_size=l_cs_size[i],color="red")
    else:
        geo1.add("",[l_cp[i]],type_="scatter",symbol_size=l_cs_size[i],color="red")

geo1.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo1.set_global_opts(visualmap_opts=opts.VisualMapOpts(min_=-1000,max_=45000,orient="horizontal",pos_bottom="80px",pos_left="80px"),
                    title_opts=opts.TitleOpts(title="各城市销售额及利润分析",subtitle="大小表示销售额,颜色表示利润",pos_left="280px",pos_top="35px"))
geo1.render_notebook()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

3、各品类销售额对比

柱状图、时间线:

tl = Timeline(init_opts=opts.InitOpts(width="900px",height="450px",theme=ThemeType.DARK))
tl.add_schema(is_auto_play=True)
x = ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
for i in range(2015,2019):
    data_i = data2[data2["年"]==str(i)]
    bar_2 = (
        Bar()
        .add_xaxis(x)
        .add_yaxis("家具产品",data_i[data_i["产品类别"]=="家具产品"]["销售额"].tolist())
        .add_yaxis("技术产品",data_i[data_i["产品类别"]=="技术产品"]["销售额"].tolist())
        .add_yaxis("办公用品",data_i[data_i["产品类别"]=="办公用品"]["销售额"].tolist())
    )
    bar_2.set_global_opts(title_opts=opts.TitleOpts(title="各品类销售额对比",pos_top="10px",pos_left="100px"),
                          legend_opts=opts.LegendOpts(pos_top="13px"))
    tl.add(bar_2,"{}年".format(i))
tl.render_notebook()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

4、区域销售走势

堆叠面积图、数据缩放控件:

line4 = Line(init_opts=opts.InitOpts(width="800px",height="500px",theme=ThemeType.DARK))
line4.add_xaxis(x4_date)
line4.add_yaxis("华南",y4_hn,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.add_yaxis("华北",y4_hb,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.add_yaxis("华东",y4_hd,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.add_yaxis("东北",y4_db,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.add_yaxis("西北",y4_xb,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.add_yaxis("西南",y4_xn,stack=True,areastyle_opts=opts.AreaStyleOpts(opacity=0.9),is_smooth=True)
line4.set_global_opts(datazoom_opts=opts.DataZoomOpts(is_show=True,type_="slider",range_start=80,range_end=80.8),
                      title_opts=opts.TitleOpts(title="区域销售走势",pos_left="130px",pos_top="5px"),
                      legend_opts=opts.LegendOpts(pos_top="13px",pos_left="350px"))
line4.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
line4.render_notebook()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

5、年度区域销售占比

饼图、环形南丁格尔图、:

pie5 = Pie(init_opts=opts.InitOpts(width="800px",height="800px",theme=ThemeType.DARK))
pie5.add("2015年",l5_2015,rosetype="radius",radius=["12%","30%"],center=["25%","300px"])
pie5.add("2016年",l5_2016,rosetype="radius",radius=["12%","30%"],center=["75%","300px"])
pie5.add("2017年",l5_2017,rosetype="radius",radius=["12%","30%"],center=["25%","590px"])
pie5.add("2018年",l5_2018,rosetype="radius",radius=["12%","30%"],center=["75%","590px"])
pie5.set_global_opts(legend_opts=opts.LegendOpts(pos_top="90px"),
                     title_opts=opts.TitleOpts(title="   年度区域销售占比",subtitle="2015年/2016年/2017年/2018年",pos_top="20px",pos_left="300px"))
pie5.set_series_opts(label_opts=opts.LabelOpts(color="write",formatter="{d}%",position="top"))
pie5.add("",[["",1]],radius=["0%","0%"],center=["25%","300px"],label_opts=opts.LabelOpts(position="inside",formatter="2015",font_size=20),
         tooltip_opts=opts.TooltipOpts(is_show=False,trigger="none"))
pie5.add("",[["",1]],radius=["0%","0%"],center=["75%","300px"],label_opts=opts.LabelOpts(position="inside",formatter="2016",font_size=20),
         tooltip_opts=opts.TooltipOpts(is_show=False,trigger="none"))
pie5.add("",[["",1]],radius=["0%","0%"],center=["25%","590px"],label_opts=opts.LabelOpts(position="inside",formatter="2017",font_size=20),
         tooltip_opts=opts.TooltipOpts(is_show=False,trigger="none"))
pie5.add("",[["",1]],radius=["0%","0%"],center=["75%","590px"],label_opts=opts.LabelOpts(position="inside",formatter="2018",font_size=20),
         tooltip_opts=opts.TooltipOpts(is_show=False,trigger="none"))
pie5.render_notebook()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17