def test_gauage_label_setting(fake_writer): c = Gauge().add( "", [("完成率", 66.6)], detail_label_opts=opts.GaugeDetailOpts(formatter="{value}"), title_label_opts=opts.GaugeTitleOpts( font_size=40, color="blue", font_family="Microsoft YaHei" ), ) c.render() _, content = fake_writer.call_args[0] assert_in("title", content) assert_in("detail", content)
def gauge(dados, componente, metrica, temaEscuro=False, abrir_local=False): if (temaEscuro): gauge = Gauge(init_opts=opts.InitOpts(theme=ThemeType.CHALK)) else: gauge = Gauge(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE)) gauge.add('', [(componente, dados)], start_angle=190, end_angle=-10, title_label_opts=opts.GaugeTitleOpts(font_size=28, color=("white" if temaEscuro else "black")), detail_label_opts=opts.GaugeDetailOpts(font_size=36, offset_center=[0, "25%"], formatter=(str(dados) + str(metrica)), color=("white" if temaEscuro else "black"))) gauge.set_global_opts(title_opts=opts.TitleOpts(title="Uso de " + componente)) make_snapshot(driver, gauge.render("chart.html"), "chart.png") abrirGrafico(abrir_local) return 0
from pyecharts.charts import Gauge from pyecharts import options as opts c = (Gauge().add( "业务指标", [("完成率", 55.5)], split_number=5, axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30)), detail_label_opts=opts.GaugeDetailOpts(formatter="{value}"), ).set_global_opts( title_opts=opts.TitleOpts(title="Gauge-分割段数-Label"), legend_opts=opts.LegendOpts(is_show=False), ).render("Gauge_splitnum_label.html"))
def showData(request): data = {} # 数据类型 float SuccessRate = 1.0 c1 = (Liquid(init_opts=opts.InitOpts(width="350px", height="350px")).add( series_name="平均成功率", data=[SuccessRate, SuccessRate], tooltip_opts=liquid_format(SuccessRate), )) # 数据类型 hours.minute timeCost = 5.45 c2 = (Gauge(init_opts=opts.InitOpts(width="300px", height="300px")).add( series_name="平均成功耗时", data_pair=[("耗时", timeCost)], min_=0, max_=24, split_number=12, title_label_opts=opts.LabelOpts(font_size=20, color="#C23531", font_family="Microsoft YaHei"), detail_label_opts=opts.GaugeDetailOpts(offset_center=[0, "30%"], formatter="{value}h"), ).set_global_opts( legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, formatter=gauge_format(timeCost)), )) # 数据类型:考点+排队人数 location = ["山西", "四川", "山东"] values = [13, 42, 2] c3 = (PictorialBar(init_opts=opts.InitOpts( height="500px")).add_xaxis(location).add_yaxis( "", values, label_opts=opts.LabelOpts(is_show=False), symbol_size=40, symbol_repeat="fixed", symbol_offset=[0, -5], is_symbol_clip=True, symbol="image://../../static/img/wait_people.svg", category_gap="10px", gap="10px", ).reversal_axis().set_global_opts( xaxis_opts=opts.AxisOpts(is_show=False), yaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_show=False), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(opacity=0)), ), )) points = ["四川大学", "成都理工大学", "湖南大学"] counts = [4, 5, 1] # 时.分 cost = [4.20, 0.32, 7.40] c4 = (Bar().add_xaxis(xaxis_data=points).add_yaxis( series_name="总人数", y_axis=counts, yaxis_index=0, label_opts=opts.LabelOpts(is_show=False), ).add_yaxis( series_name="时耗", y_axis=cost, yaxis_index=1, label_opts=opts.LabelOpts(is_show=False), ).extend_axis(yaxis=opts.AxisOpts( name="时耗", type_="value", min_=0, max_=24, interval=4, axislabel_opts=opts.LabelOpts(formatter="{value}h"), )).set_global_opts( tooltip_opts=opts.TooltipOpts( is_show=True, trigger="axis", formatter="{b}<br>{a0}: {c0}<br>{a1}: {c1}h"), xaxis_opts=opts.AxisOpts( type_="category", axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"), ), )) data['averageRate'] = c1.render_embed() data['averageCost'] = c2.render_embed() data['pointCurrent'] = c3.render_embed() data['pointDetail'] = c4.render_embed() return render(request, 'showEcharts.html', { 'active_menu': 'charts', 'data': data })
c = (Funnel().add( "商品", [list(z) for z in zip(Faker.choose(), Faker.values())], sort_="ascending", label_opts=opts.LabelOpts(position="inside"), ).set_global_opts(title_opts=opts.TitleOpts( title="Funnel-Sort(ascending)")).render("funnel_sort_ascending.html")) # 仪表盘 from pyecharts.charts import Gauge g = (Gauge().add( "", [("完成率", 66.6)], detail_label_opts=opts.GaugeDetailOpts( offset_center=[0, "40%"], font_size=30, ), ).set_global_opts(title_opts=opts.TitleOpts( title="Gauge-基本示例")).render("gauge_base.html")) # 关系图 from pyecharts.charts import Graph nodes = [ { "name": "结点1", "symbolSize": 10 }, { "name": "结点2", "symbolSize": 20 },
def to_echarts(sql): from pyecharts import options as opts from pyecharts.charts import Gauge dfsql = kl_class.dfMysql() df = dfsql.select_mysql(sql) #删除重复值 df.drop_duplicates(inplace=True) #删除缺失值 #print(len(df)) df.dropna(axis=0, how='all', inplace=True) #print(len(df)) #填充缺失值 #df.fillna('未填写',inplace=True) #删除空格 df['是否完成整改']=df['是否完成整改'].map(str.strip) start_date='2020-1-1' end_date = pd.to_datetime(datetime.date.today()).date() df= df[(df['开始时间'] >= pd.to_datetime(start_date).date()) & (df['结束时间'] <= end_date) ] df_doing=df[df['是否完成整改']=='否'] df_split = df_doing.to_dict(orient='split') tb = table_base(df_split['columns'], df_split['data']) tb.render("doing.html") zg=df['是否完成整改'].value_counts() rat=round(100*(zg['是']/len(df)),2) ajk_name=['李黎','陈虹伍','杨和俊','陈斌','何艳琪','郭晶晶','杨建平'] yjk_name=['洪永健','和定繁','王玺','周浩然','高璐'] df_split1=kl_class.split_record(df, '整改责任人', '、') df_ajk=df_split1[df_split1['整改责任人'].isin(ajk_name)] zg_ajk=df_ajk['是否完成整改'].value_counts() rat_ajk=round(100*(zg_ajk['是']/len(df_ajk)),2) df_yjk=df_split1[df_split1['整改责任人'].isin(yjk_name)] zg_yjk=df_yjk['是否完成整改'].value_counts() rat_yjk=round(100*(zg_yjk['是']/len(df_yjk)),2) #交叉表 ct=pd.crosstab(index=df_split1['整改责任人'], columns=df_split1['是否完成整改'], margins=True) #ct.columns=[] ct['rat']=round(100*(ct['是']/ct['All']),2) ct.sort_values('rat',ascending=False,inplace=True) t=[] for column in ct.iteritems(): if column[0]=='rat': for i in range(len(ct)): if column[1].index[i]!='All': t.append(column[1].index[i]+str(column[1].values[i])+'%\n') tn=''.join(t) # a = df[''].str.split('、', expand=True).stack().value_counts() # print(a) text = "安全监管部完成率{0}%\n\n安全监察科完成率{1}%:\n\n应急管理科完成率{2}%:\n\n{3}".format(rat, rat_ajk, rat_yjk, tn) c = ( # Gauge(init_opts=opts.InitOpts(width="1200px", height="600px"))#设置画布尺寸 Gauge(init_opts=opts.InitOpts( js_host=r"D:\JGY\600-Data\004-auxiliary辅助文件\\", width="1200px", height="600px", renderer="RenderType.SVG", page_title="立行立改问题库", theme="white") ) .add( series_name="安全监管部", data_pair=[("安全监管部", rat)], is_selected=True, min_=0, max_=100, split_number=10, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#FF0033"), (0.7, "#FF6600"), (1, "#009900")], width=30 ) ), radius="80%", start_angle=150, end_angle=30, is_clock_wise=True, title_label_opts=opts.GaugeTitleOpts( font_size=20, color="blue", font_family="Microsoft YaHei", offset_center=[0, "-55%"], ), detail_label_opts=opts.GaugeDetailOpts( is_show=True, background_color='red', border_width=0, border_color='blue', offset_center=[0, "-40%"], color="white", font_style="oblique", font_weight="bold", font_family="Microsoft YaHei", font_size=26, border_radius=120, padding=[4, 4, 4, 4], formatter="{value}%" ), pointer=opts.GaugePointerOpts( # 是否显示指针。 is_show=True, # 指针长度,可以是绝对数值,也可以是相对于半径的半分比。 length="80%", # 指针宽度。 width=12, ), ) .add( series_name="安全监察科", data_pair=[("安全监察科", rat_ajk)], is_selected=True, min_=0, max_=100, split_number=10, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#FF0033"), (0.7, "#FF6600"), (1, "#009900")], width=30 ) ), radius="80%", start_angle=265, end_angle=155, is_clock_wise=True, title_label_opts=opts.GaugeTitleOpts( font_size=20, color="blue", font_family="Microsoft YaHei", offset_center=[-100, "25%"], ), detail_label_opts=opts.GaugeDetailOpts( is_show=True, background_color='red', border_width=0, border_color='blue', offset_center=[-100, "40%"], color="white", font_style="oblique", font_weight="bold", font_family="Microsoft YaHei", font_size=26, border_radius=120, padding=[4, 4, 4, 4], formatter="{value}%" ), pointer=opts.GaugePointerOpts( # 是否显示指针。 is_show=True, # 指针长度,可以是绝对数值,也可以是相对于半径的半分比。 length="50%", # 指针宽度。 width=8, ), ) .add( series_name="应急管理科", data_pair=[("应急管理科", rat_yjk)], is_selected=True, min_=0, max_=100, split_number=10, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#FF0033"), (0.7, "#FF6600"), (1, "#009900")], width=30 ) ), radius="80%", start_angle=385, end_angle=275, is_clock_wise=True, title_label_opts=opts.GaugeTitleOpts( font_size=20, color="blue", font_family="Microsoft YaHei", offset_center=[100, "25%"], ), detail_label_opts=opts.GaugeDetailOpts( is_show=True, background_color='red', border_width=0, border_color='blue', offset_center=[100, "40%"], color="white", font_style="oblique", font_weight="bold", font_family="Microsoft YaHei", font_size=26, border_radius=120, padding=[4, 4, 4, 4], formatter="{value}%" ), pointer=opts.GaugePointerOpts( # 是否显示指针。 is_show=True, # 指针长度,可以是绝对数值,也可以是相对于半径的半分比。 length="50%", # 指针宽度。 width=8, ), ) .set_global_opts( title_opts=opts.TitleOpts( title="立行立改问题库完成率", title_link="https:www.163.com", title_target="self", subtitle=text, subtitle_link="doing.html", subtitle_target="blank", pos_left="left", ) ) .render("gauge_lxlxwtk.html") )
#导入仪表盘 from pyecharts.charts import Gauge from pyecharts import options as opts from pyecharts.globals import ThemeType as tt #若是要显示在仪表盘内的文字,则应该写在第二个格式为[(数据项名,值),(数据项名,值)]的字典里 gauge = ( #改变背景颜色 Gauge(init_opts=opts.InitOpts(theme=tt.LIGHT)) # #is_clock_wise为改变是顺着还是逆着,split_number:仪表盘分割的段数,min_,max_:最大值,最小值 # .add('完成率',[('',7777)],is_clock_wise=True,split_number=10,min_=1000,max_=10000,radius="100%") # .render() #配置仪表盘的 .add('完成率',[('',66.66)],radius='80%',detail_label_opts=opts.GaugeDetailOpts( font_style='italic',#字体的样式,可选的有normal,italic,oblique font_family='serif',#字体 font_size=20,#字号 font_weight='lighter',#文字粗细,bord,border,lighter offset_center=[0,'-60%']#距离中心的偏移值,第一个是水平偏移,第二个是垂直偏移 ), #配置指针的 pointer=opts.GaugePointerOpts( length=100,#length指的是指针长度 width=8#宽度,可以是绝对值也可以是相对数值 )) #改变仪表盘的颜色 .set_series_opts( axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[[0.3, "#67e0e3"], [0.7, "#37a2da"], [1, "#fd666d"]], width=30 ) ) )