1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| from pyecharts.charts import Bar, Line, Pie, Page from pyecharts import options as opts import pandas as pd import numpy as np
months = ["1月", "2月", "3月", "4月", "5月", "6月"] sales = [120, 150, 180, 140, 200, 220] profit = [30, 40, 50, 35, 55, 65] regions = ["华北", "华东", "华南", "西南"] region_sales = [350, 420, 380, 280]
line = ( Line() .add_xaxis(months) .add_yaxis("销售额", sales, is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])) .add_yaxis("利润", profit, is_smooth=True) .set_global_opts( title_opts=opts.TitleOpts(title="月度业绩趋势"), toolbox_opts=opts.ToolboxOpts(), ) )
pie = ( Pie() .add("", [list(z) for z in zip(regions, region_sales)], radius=["40%", "70%"]) .set_global_opts(title_opts=opts.TitleOpts(title="地区销售占比")) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%")) )
products = ["产品A", "产品B", "产品C", "产品D", "产品E"] product_sales = [320, 280, 250, 220, 180]
bar = ( Bar() .add_xaxis(products) .add_yaxis("销量", product_sales) .reversal_axis() .set_series_opts(label_opts=opts.LabelOpts(position="right")) .set_global_opts(title_opts=opts.TitleOpts(title="产品销量排行")) )
page = Page(layout=Page.DraggablePageLayout, page_title="销售数据大屏") page.add( line, pie, bar, ) page.render("dashboard.html")
print("数据大屏已生成:dashboard.html") print("请在浏览器中打开查看")
|