数据可视化大屏(超市数据分析与可视化)
发布时间
阅读量:
阅读量
数据可视化大屏(超市数据分析与可视化)
资源自己下载


import pandas as pd
from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.commons.utils import JsCode
path = './1.csv'
df = pd.read_csv(path)
df.columns = ['行ID', '订单ID', '订单日期', '发货日期', '发货方式', '客户ID', '客户名称', '客户类型', '国家', '城市',
'州', '邮政编码', '所属区域', '产品ID', '产品类别', '产品子类别', '产品名称', '销售额', '产品数量',
'提供折扣', '利润/亏损']
df['日期'] = pd.to_datetime(df['订单日期'])
df['年份'] = pd.to_datetime(df['订单日期']).dt.year
df['月份'] = pd.to_datetime(df['订单日期']).dt.month
df['年-月'] = df['年份'].astype('str') + '-' + df['月份'].astype('str')
a1 = df[['年份', '州', '销售额']].groupby(['年份', '州']).sum().round(2).reset_index()
datemap = a1['年份'].unique()
a2014 = a1[a1['年份'] == 2014]
a2015 = a1[a1['年份'] == 2015]
a2016 = a1[a1['年份'] == 2016]
a2017 = a1[a1['年份'] == 2017]
datamap = [a2014, a2015, a2016, a2017]
tl_map = (
Timeline(
init_opts=opts.InitOpts(
theme='dark'
)
)
.add_schema(
is_auto_play=True, # 是否自动播放
play_interval=1500, # 播放速度
is_loop_play=True, # 是否循环播放
)
)
for data_map, date_map in zip(datamap, datemap):
map_1 = (
Map(
init_opts=opts.InitOpts(
theme='dark'
)
)
.add(
'销售额',
[list(i) for i in zip(data_map['州'], data_map['销售额'])],
'美国'
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
is_show=True,
max_=data_map['销售额'].max()
),
title_opts=opts.TitleOpts(
title='每年销售额分布地图',
),
yaxis_opts=opts.AxisOpts(
axistick_opts=opts.AxisTickOpts(is_show=False)
)
)
)
tl_map.add(map_1, f'{date_map}年')
b1 = df[['年份', '州', '销售额']].groupby(['年份', '州']).sum().round(2).reset_index()
datepie = b1['年份'].unique()
b2014 = b1[b1['年份'] == 2014]
b2015 = b1[b1['年份'] == 2015]
b2016 = b1[b1['年份'] == 2016]
b2017 = b1[b1['年份'] == 2017]
b2014['销售占比'] = ((b2014['销售额'] / b2014['销售额'].sum()) * 100).round(2)
b2015['销售占比'] = ((b2015['销售额'] / b2015['销售额'].sum()) * 100).round(2)
b2016['销售占比'] = ((b2016['销售额'] / b2016['销售额'].sum()) * 100).round(2)
b2017['销售占比'] = ((b2017['销售额'] / b2017['销售额'].sum()) * 100).round(2)
pieb = [b2014.sort_values(by='销售额', ascending=False), b2015.sort_values(by='销售额', ascending=False),
b2016.sort_values(by='销售额', ascending=False), b2017.sort_values(by='销售额', ascending=False)]
tl_pie = (
Timeline(
init_opts=opts.InitOpts(
theme='dark'
)
)
.add_schema(
is_auto_play=True, # 是否自动播放
play_interval=1500, # 播放速度
is_loop_play=True, # 是否循环播放
)
)
for data_pie, date_pie in zip(pieb, datepie):
pie = (
Pie(
init_opts=opts.InitOpts(
theme='dark'
)
)
.add(
'',
[list(i) for i in zip(data_pie['州'], data_pie['销售占比'])],
)
.set_global_opts(
title_opts=opts.TitleOpts(
title='每年各个州销售额占比',
title_textstyle_opts=dict(color='white'),
),
legend_opts=opts.LegendOpts(
type_='scroll',
orient='vertical',
pos_left='86%',
textstyle_opts=opts.TextStyleOpts(
color='white', # 颜色
font_weight='bolder', # 加粗
),
)
)
.set_series_opts(
label_opts=opts.LabelOpts(
formatter='{b} {c}%',
color='white',
font_weight='bolder', # 加粗
font_style='oblique', # 斜体
)
)
)
tl_pie.add(pie, date_pie)
date = df.sort_values(by='日期')['年-月'].unique()
data = []
for i in date:
data1 = df[df['年-月'] == i][['产品名称', '销售额']].groupby(['产品名称']).sum().round(2).reset_index().sort_values(
by='销售额', ascending=False)[:10]
data1 = data1.sort_values(by='销售额', ascending=True)
data.append(data1)
tl = (
Timeline(
init_opts=opts.InitOpts(
theme='dark',
)
)
.add_schema(
is_auto_play=True, # 是否自动播放
play_interval=1500, # 播放速度
is_loop_play=True, # 是否循环播放
)
)
for i, date1 in zip(date, data):
bar1 = (
Bar(
init_opts=opts.InitOpts(
theme='dark',
)
)
.add_xaxis(date1['产品名称'].tolist())
.add_yaxis(
'销售额',
date1['销售额'].tolist(),
category_gap='40%',
itemstyle_opts={
'normal': {
'color': JsCode(
'''new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,color: 'rgba(0, 244, 255, 1)'}
,{offset: 1,color: 'rgba(0, 77, 167, 1)'}])
'''
),
'shadowBlur': 15,
'barBorderRadius': [100, 100, 100, 100],
'shadowColor': "#0089c7",
}
},
)
.reversal_axis()
.set_global_opts(
# 标题设置
title_opts=opts.TitleOpts(
title='每月各产品销售额top10榜单', # 主标题
pos_left='center', # 标题展示位置
title_textstyle_opts=dict(color='white'), # 设置标题字体颜色
subtitle_textstyle_opts=dict(color='#white')
),
legend_opts=opts.LegendOpts(
pos_left='right',
pos_top='3%',
orient='vertical',
textstyle_opts=opts.TextStyleOpts(
color='white',
font_weight='bolder',
font_style='oblique', # 斜体
),
),
tooltip_opts=opts.TooltipOpts(
is_show=True,
trigger='axis',
axis_pointer_type='cross',
),
yaxis_opts=opts.AxisOpts(
splitline_opts=opts.SplitLineOpts(
is_show=False
),
axistick_opts=opts.AxisTickOpts(
is_show=False
),
axislabel_opts=opts.LabelOpts( # 坐标轴标签配置
font_size=13, # 字体大小
color='white',
font_weight='bolder',
font_style='oblique', # 斜体
),
),
xaxis_opts=opts.AxisOpts(
axistick_opts=opts.AxisTickOpts(
is_show=True
),
splitline_opts=opts.SplitLineOpts(
is_show=False
),
axisline_opts=opts.AxisLineOpts(
is_show=True
),
axislabel_opts=opts.LabelOpts( # 坐标轴标签配置
font_size=13, # 字体大小
color='white',
font_weight='bolder',
font_style='oblique', # 斜体
),
),
)
.set_series_opts(
label_opts=opts.LabelOpts(
position='right',
color='white',
font_weight='bolder',
)
)
)
tl.add(bar1, i)
sale_data = df.sort_values(by='日期')[['年份', '日期', '销售额', '利润/亏损']]. \
groupby(['年份', '日期']).sum().round(2).reset_index()
year_lis = sale_data['年份'].unique().tolist()
sale_data1 = sale_data[sale_data['年份'] == 2014]
sale_data2 = sale_data[sale_data['年份'] == 2015]
sale_data3 = sale_data[sale_data['年份'] == 2016]
sale_data4 = sale_data[sale_data['年份'] == 2017]
sale_data_lis = [sale_data1, sale_data2, sale_data3, sale_data4]
tl1 = (
Timeline(
init_opts=opts.InitOpts(
theme='dark',
width='1200px', # 设置图的宽度
height='700px' # 设置图的高度
)
)
.add_schema(
is_auto_play=True, # 是否自动播放
play_interval=1500, # 播放速度
is_loop_play=True, # 是否循环播放
)
)
for table, data in zip(year_lis, sale_data_lis):
line1 = Line(
init_opts=opts.InitOpts(
theme='dark', # 设置主题
)
)
line1.add_xaxis(data['日期'].tolist())
line1.add_yaxis(
'销售额',
data['销售额'].tolist(),
is_symbol_show=False, # 是否显示数据标签点
is_smooth=True, # 设置曲线平滑
label_opts=opts.LabelOpts(
is_show=False,
),
# 线条粗细阴影设置
linestyle_opts={
"normal": {
"color": "#E47085", # 线条颜色
"shadowColor": '#E4708560', # 阴影颜色和不透明度
"shadowBlur": 8, # 阴影虚化大小
"shadowOffsetY": 20, # 阴影y偏移量
"shadowOffsetX": 20, # 阴影x偏移量
"width": 5 # 线条粗细
},
},
)
line1.add_yaxis(
'利润/亏损',
data['利润/亏损'].tolist(),
is_symbol_show=False, # 是否显示数据标签点
is_smooth=True, # 设置曲线平滑
label_opts=opts.LabelOpts(
is_show=True, # 是否显示数据
),
# 线条粗细阴影设置
linestyle_opts={
"normal": {
"color": "#44B2BE", # 线条颜色
"shadowColor": '#44B2BE60', # 阴影颜色和不透明度
"shadowBlur": 8, # 阴影虚化大小
"shadowOffsetY": 20, # 阴影y偏移量
"shadowOffsetX": 20, # 阴影x偏移量
"width": 5 # 线条粗细
},
},
)
line1.set_global_opts(
# 标题设置
title_opts=opts.TitleOpts(
title='销售额、利润在时间维度的变化', # 主标题
pos_left='center', # 标题展示位置
),
# 图例设置
legend_opts=opts.LegendOpts(
pos_left='right', # 图例显示位置
),
tooltip_opts=opts.TooltipOpts(
is_show=True, # 是否使用提示框
trigger='axis', # 触发类型
is_show_content=True,
axis_pointer_type='cross', # 指示器类型,鼠标移动到图表区可以查看效果
),
datazoom_opts=opts.DataZoomOpts(
range_start=0, # 开始范围
range_end=25, # 结束范围
orient='vertical', # 设置为垂直布局
),
yaxis_opts=opts.AxisOpts(
is_show=True,
splitline_opts=opts.SplitLineOpts(is_show=False), # 分割线
axistick_opts=opts.AxisTickOpts(is_show=False), # 刻度不显示
axislabel_opts=opts.LabelOpts( # 坐标轴标签配置
font_weight='bolder' # 字重
),
), # 关闭Y轴显示
xaxis_opts=opts.AxisOpts(
boundary_gap=False, # 两边不显示间隔
axistick_opts=opts.AxisTickOpts(is_show=True), # 刻度不显示
splitline_opts=opts.SplitLineOpts(is_show=False), # 分割线不显示
axisline_opts=opts.AxisLineOpts(is_show=True), # 轴不显示
axislabel_opts=opts.LabelOpts( # 坐标轴标签配置
font_weight='bolder' # 字重
),
),
)
tl1.add(line1, table)
zxsa = int(df['销售额'].sum())
zdds = len(df)
bjlr = int(df['利润/亏损'].mean())
c = (
Pie(
init_opts=opts.InitOpts(
theme='dark',
bg_color=JsCode(
'''new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
offset: 0,color: 'rgba(16,12,42,1.00)'}
,{offset: 1,color: 'rgba(0, 77, 167, 1)'}], false)
'''
),
)
)
.set_global_opts(
legend_opts=opts.LegendOpts(
is_show=False
),
title_opts=opts.TitleOpts(
title='超市数据可视化大屏',
pos_left='center',
pos_top='middle',
title_textstyle_opts=opts.TextStyleOpts(
font_size=36
)
)
)
)
c1 = (
Pie(
init_opts=opts.InitOpts(
theme='dark',
)
)
.set_global_opts(
legend_opts=opts.LegendOpts(
is_show=False
),
title_opts=opts.TitleOpts(
title=bjlr,
subtitle='平均利润',
pos_left='center',
pos_top='middle',
title_textstyle_opts=opts.TextStyleOpts(
font_size=36
)
)
)
)
c2 = (
Pie(
init_opts=opts.InitOpts(
theme='dark',
)
)
.set_global_opts(
legend_opts=opts.LegendOpts(
is_show=False
),
title_opts=opts.TitleOpts(
title=zdds,
subtitle='总订单数',
pos_left='center',
pos_top='middle',
title_textstyle_opts=opts.TextStyleOpts(
font_size=36
)
)
)
)
c3 = (
Pie(
init_opts=opts.InitOpts(
theme='dark',
)
)
.set_global_opts(
legend_opts=opts.LegendOpts(
is_show=False
),
title_opts=opts.TitleOpts(
title=zxsa,
subtitle='总销售额',
pos_left='center',
pos_top='middle',
title_textstyle_opts=opts.TextStyleOpts(
font_size=36
)
)
)
)
page = Page(layout=Page.DraggablePageLayout)
# page.add(c, tl_map, tl, tl_pie, tl1, c1, c2, c3).render()
Page.save_resize_html(source='./render.html', cfg_file='./chart_config.json', dest='./超市数据可视化大屏最终效果.html')
全部评论 (0)
还没有任何评论哟~
