def member7_chart(): # 最近七天注册人数 line1 = Line() line1.add_xaxis(list(d7_reg_count_dict.keys())) line1.add_yaxis("人数", list(d7_reg_count_dict.values()), linestyle_opts=opts.LineStyleOpts(width=5)) line1.set_global_opts(title_opts=opts.TitleOpts(title="最近七天注册人数")) return line1.dump_options_with_quotes()
def line_chart(): # 折线图 line = Line() x_y_axis = get_chart_data() line.add_xaxis(x_y_axis[0]) for j in x_y_axis[1]: for key, value in j.items(): line.add_yaxis(key, value, areastyle_opts=opts.AreaStyleOpts(opacity=1), label_opts=opts.LabelOpts(is_show=False)) line.set_series_opts( # linestyle_opts=opts.LineStyleOpts( # width=5, # opacity=1, # type_='solid', # ) markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="min", name="最小值"), ]), ) line.set_global_opts( title_opts=opts.TitleOpts( title="API耗时统计", subtitle="生产环境", pos_left="30%", title_textstyle_opts=opts.TextStyleOpts(color='red'), subtitle_textstyle_opts=opts.TextStyleOpts(color='blue')), xaxis_opts=opts.AxisOpts( name="运行时间", type_="category", boundary_gap=False, # axislabel_opts=opts.LabelOpts(rotate=15) ), yaxis_opts=opts.AxisOpts(name="实际的响应时间(单位:秒)", # min_=0, # max_=20 ), legend_opts=opts.LegendOpts(type_='scroll', selected_mode='multiple', pos_left='right', pos_top='10%', orient='vertical'), tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line"), toolbox_opts=opts.ToolboxOpts(is_show=True, pos_left='right'), visualmap_opts=opts.VisualMapOpts(is_show=True, type_="size", min_=0, max_=20, range_text=["最大值", "最小值"]), datazoom_opts=[opts.DataZoomOpts(range_start=50, range_end=100)], ) line = line.dump_options_with_quotes() return line
def order7_chart(): # 最近七天订单确认成交数量 line2 = Line() line2.add_xaxis(list(d7_order_finish_dict.keys())) line2.add_yaxis("数量", list(d7_order_finish_dict.values()), itemstyle_opts=opts.ItemStyleOpts(color='blue'), linestyle_opts=opts.LineStyleOpts(width=5)) line2.set_global_opts(title_opts=opts.TitleOpts(title="最近七天订单确认成交数量")) return line2.dump_options_with_quotes()
def report_cpu(host_id=int): chart_data = MonitorCpuService().find_top_rate(host_id, 10) line = Line() line.add_xaxis([row[1] for row in chart_data]) line.add_yaxis("使用率(%)", [round(row[0] * 100, 2) for row in chart_data]) line.set_global_opts( xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-40)), yaxis_opts=opts.AxisOpts(max_=100), legend_opts=opts.LegendOpts(is_show=False), title_opts=opts.TitleOpts(title='CPU使用率(%)')) return line.dump_options_with_quotes()
def testinfo_get(): df = TestInfo().df[-12:] xdata = df['月份'].tolist() ratio = df['通过率'].tolist() fig = Line() fig.add_xaxis(xdata) fig.add_yaxis('一次通过率', ratio) fig.set_global_opts( title_opts=opts.TitleOpts(title="最近12月测试通过率"), yaxis_opts=opts.AxisOpts( name='通过率', type_='value', axislabel_opts=opts.LabelOpts(formatter="{value} %")), ) return fig.dump_options_with_quotes()