实际应用:常态化性能压测数据统计
import random
from pyecharts.charts import Line, Bar, Grid, Pie, Page
from pyecharts import options as opts
# 查询过去 8 次数据
time_range = 8
interface = ['充值', '赠送', '支付', '支付回退', '预授权']
bar = (
Bar()
.add_xaxis(interface)
.add_yaxis("支付", [113, 106, 122, 128, 128, 55, 45])
.add_yaxis("券", [75, 46, 75, 65, 118, 15, 70])
.add_yaxis("限额限频", [173, 146, 175, 165, 218, 115, 170])
.add_yaxis("全流程", [65, 46, 70, 65, 108, 45, 40])
.set_global_opts(title_opts=opts.TitleOpts(title="TPS(当前版本)"))
)
line = Line().add_xaxis([f"2023-07-0{i} 05:04:2{i}" for i in range(1, time_range)]). \
add_yaxis(interface[0], [random.randint(100, 150) for _ in range(time_range)])
for i, inter in enumerate(interface):
line.add_yaxis(inter, [random.randint(10 * (i + 1), 100) for _ in range(time_range)],
label_opts=opts.LabelOpts(is_show=False))
line.set_global_opts(
title_opts=opts.TitleOpts(title="性能趋势(支付)", pos_top="48%"),
legend_opts=opts.LegendOpts(pos_top="48%"),
yaxis_opts=opts.AxisOpts(
name="TPS",
axislabel_opts=opts.LabelOpts(is_show=False), # 设置label_opts参数
)
)
grid = Grid().add(bar, grid_opts=opts.GridOpts(pos_bottom="60%")).add(line, grid_opts=opts.GridOpts(pos_top="60%"))
pie = Pie()
pie.add("-", [("已剔除", 2), ("梳理中", 2), ("已完成", 15), ("优化中", 13), ("时间规划中", 13)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="摸底系统统计"), )
# - `{a}`:表示系列名称。`{b}`:表示数据类别 `{c}`:表示数据值(如10、25、50和15)。`{d}`:表示数据所占的百分比。- `{@[index]}`:表示数据数组中索引为`index`的值。
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{a}{b}: {c} ({d}%)"))
page = Page()
page.add(grid)
page.add(pie)
page.render()