def report(request): """返回慢SQL历史趋势""" checksum = request.GET.get('checksum') cnt_data = ChartDao().slow_query_review_history_by_cnt(checksum) pct_data = ChartDao().slow_query_review_history_by_pct_95_time(checksum) cnt_x_data = [row[1] for row in cnt_data['rows']] cnt_y_data = [int(row[0]) for row in cnt_data['rows']] pct_y_data = [str(row[0]) for row in pct_data['rows']] line = Line(init_opts=opts.InitOpts(width='800', height='380px')) line.add_xaxis(cnt_x_data) line.add_yaxis("慢查次数", cnt_y_data, is_smooth=True, markline_opts=opts.MarkLineOpts(data=[ opts.MarkLineItem(type_="max", name='最大值'), opts.MarkLineItem(type_="average", name='平均值') ])) line.add_yaxis("慢查时长(95%)", pct_y_data, is_smooth=True, is_symbol_show=False) line.set_series_opts(areastyle_opts=opts.AreaStyleOpts(opacity=0.5, )) line.set_global_opts( title_opts=opts.TitleOpts(title='SQL历史趋势'), legend_opts=opts.LegendOpts(selected_mode='single'), xaxis_opts=opts.AxisOpts( axistick_opts=opts.AxisTickOpts(is_align_with_label=True), is_scale=False, boundary_gap=False, ), ) result = {"status": 0, "msg": '', "data": line.render_embed()} return HttpResponse(json.dumps(result), content_type='application/json')
def index(): date_ = db.session.query( func.distinct(CourseCount.update_at).label('update_at')).order_by( CourseCount.update_at.asc() # noqa ).all() name_ = db.session.query(Course.name).order_by(Course.id.asc() # noqa ).all() course_count_ = db.session.query( CourseCount.count, CourseCount.update_at, Course.name).join(Course, CourseCount.course_id == Course.id).order_by( CourseCount.update_at.asc(), # noqa CourseCount.course_id.asc() # noqa ).all() x_date = [_.update_at for _ in date_] y_name = [_.name for _ in name_] data = [] for name in y_name: d = list() for course_count in course_count_: if course_count.name == name: d.append(course_count.count) data.append((name, d)) c = Line().add_xaxis(x_date).set_global_opts(title_opts=opts.TitleOpts( title="腾讯课堂-课程数量走势")) for d in data: c.add_yaxis(d[0], d[1], is_connect_nones=True) return Markup(c.render_embed())
def line(): cursor = connection.cursor() cursor.execute("""SELECT DATE_FORMAT( rev.create_time, '%Y-%m-%d' ) create_time, revt.`name`, count( * ) FROM resource_event rev LEFT JOIN resource_eventtype revt ON rev.event_type_id = revt.id GROUP BY create_time, event_type_id""") rows = cursor.fetchall() name_list = [] event_type_list = [] for row in rows: name = row[0] if name not in name_list: name_list.append(name) event_type = row[1] if event_type not in event_type_list: event_type_list.append(event_type) line = Line(init_opts=opts.InitOpts(height="350px")) line.add_xaxis(name_list) for event_type in event_type_list: tmp_list = [0 for i in range(len(name_list))] for row in rows: if event_type == row[1]: index = name_list.index(row[0]) tmp_list[index] = row[2] line.add_yaxis(event_type, tmp_list, is_smooth=True) line.set_global_opts(title_opts=opts.TitleOpts(title="数量变化统计")) return line.render_embed()
def line_three_html(self, title, key, val_min, val_max, val_avg): # 实例化 line = Line(self.init_opts) # X轴 line.add_xaxis(key) # Y轴 line.add_yaxis( "最小值", val_min, is_smooth=True, # 平滑曲线 markpoint_opts=self.markpoint_opts # 标记点选项 ) line.add_yaxis( "最大值", val_max, is_smooth=True, # 平滑曲线 markpoint_opts=self.markpoint_opts # 标记点选项 ) line.add_yaxis( "平均值", val_avg, is_smooth=True, # 平滑曲线 markpoint_opts=self.markpoint_opts # 标记点选项 ) # 全局配置 line.set_global_opts( title_opts=self.title_opts_custom(title, pos_left="left"), # 标题选项 datazoom_opts=[options.DataZoomOpts()], # 缩放选项 yaxis_opts=options.AxisOpts(min_=0, max_=100), # Y轴范围 ) # 返回图表html代码 return line.render_embed()
def line_html(self, title, key, val, color=None): # 实例化 line = Line(self.init_opts) # X轴 line.add_xaxis(key) # Y轴 line.add_yaxis( "", val, markline_opts=self.markline_opts, # 标记线选项 markpoint_opts=self.markpoint_opts # 标记点选项 ) # 系列配置 line.set_series_opts( linestyle_opts=options.LineStyleOpts( opacity=0.2, # 透明度 ), # 线条样式 areastyle_opts=options.AreaStyleOpts( opacity=0.4, # 透明度 color=color # 颜色 ) # 面积样式 ) # 全局配置 line.set_global_opts( title_opts=self.title_opts_custom(title), # 标题选项 datazoom_opts=[options.DataZoomOpts()], # 缩放选项 yaxis_opts=options.AxisOpts(min_=0, max_=100), # Y轴范围 ) # 返回图表html代码 return line.render_embed()
def line_three_html(self, title, key, val_min, val_max, val_avg): line = Line(init_opts=opts.InitOpts(width="100%", height="300px")) line.set_global_opts( title_opts=opts.TitleOpts( title=title, title_textstyle_opts=opts.TextStyleOpts(color="black", font_size=14), pos_left="left", ), # 增添x,y轴以及内部的缩放 datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=100)], yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)) ) line.add_xaxis(key) line.add_yaxis( "最小值", val_min, is_smooth=True, markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="min", name="最小值"), opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="average", name="平均值"), ] ), ) line.add_yaxis( "最大值", val_max, is_smooth=True, markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="min", name="最小值"), opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="average", name="平均值"), ] ), ) line.add_yaxis( "平均值", val_avg, is_smooth=True, markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="min", name="最小值"), opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="average", name="平均值"), ] ), ) return line.render_embed()
def catchart(request): line = Line(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) # form = RawCategoryForm(request.POST or None) p = request.POST.get('pp_name') pp = Product.objects.get(p_ID=p) pp_n = pp.p_name print(type(p)) #an = int(request.POST.get('a_amount')) #bn = int(request.POST.get('b_amount')) #cn = int(request.POST.get('c_amount')) an = 1230 bn = 560 cn = 850 ac = 0 bc = 0 cc = 0 aq = 0 bq = 0 cq = 0 ad = Order.objects.filter(d_ID='1', p_ID=p) bd = Order.objects.filter(d_ID='2', p_ID=p) cd = Order.objects.filter(d_ID='3', p_ID=p) for q in ad: aq += q.o_amount for w in bd: bq += w.o_amount for e in cd: cq += e.o_amount ac = round(((aq / an) * 100), 2) bc = round(((bq / bn) * 100), 2) cc = round(((cq / cn) * 100), 2) d1 = Dealer.objects.get(d_ID='1') d1_n = d1.d_name d2 = Dealer.objects.get(d_ID='2') d2_n = d2.d_name d3 = Dealer.objects.get(d_ID='3') d3_n = d3.d_name x = [d1_n, d2_n, d3_n] y1 = [ac, bc, cc] line.set_global_opts( title_opts=opts.TitleOpts(title='品類需求佔有率', subtitle='%')) line.add_xaxis(x) line.add_yaxis(pp_n, y1) return HttpResponse(line.render_embed())
def demoo(request): import store line = Line(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) #x = store.models.Product.objects.get(sortno=1) #y = store.models.Product.objects.get(sortno=2) line.add_xaxis(["1月", "2月", "3月", "4月", "5月", "6月"]) line.add_yaxis("純色腮紅", [2000, 1800, 2800, 1900, 2000, 1400]) line.add_yaxis("三色修容餅", [2100, 1900, 2400, 1600, 1850, 1600]) line.add_yaxis("柔焦無瑕粉餅", [1900, 2000, 2050, 1900, 2000, 1950]) line.add_yaxis("經典緞光唇膏", [2000, 1800, 1900, 2000, 1900, 2000]) line.add_yaxis("精萃水亮唇膏", [1700, 1500, 2200, 1800, 1670, 1700]) line.set_global_opts(title_opts=opts.TitleOpts(title='2020存貨走勢圖')) return HttpResponse(line.render_embed())
def read_ping(item_id: str, q: str = None, width: str = "800px"): line=Line(init_opts=opts.InitOpts(js_host='/static/',theme=ThemeType.LIGHT,width=width,animation_opts=opts.AnimationOpts(animation_duration=500))) #Bar() set0=(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) x=list(range(len(set0))) #x=[1,2,3,4,5,6,7,8,9] line.add_xaxis(x) list_ip=item_id.split(',') for ip in list_ip: try: data=int(ping(ip, unit='ms')) except: data=5impo00 if ip in dict_ip: pass else: dict_ip[ip]=list(set0) dict_ip[ip].append(data) dict_ip[ip].pop(0) #x=['1','2','3','4','5','6'] #y=[1,2,3,4,5,6] #y1=[0,1,2,3,4,5] #c = ( #Bar(init_opts=opts.InitOpts(js_host='./static',theme=ThemeType.LIGHT,width="2000px",animation_opts=opts.AnimationOpts(animation_duration=3000))) #line=Line(init_opts=opts.InitOpts(js_host='/static/',theme=ThemeType.LIGHT,width=width,animation_opts=opts.AnimationOpts(animation_duration=500))) #Bar() #line.add_xaxis(x) line.add_yaxis(ip, dict_ip[ip]) #line.add_yaxis('hello1', y1) #.add_yaxis("商家B", [15, 25, 16, 55, 48, 8]) #line.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=12,interval=0,rotate=-45)),title_opts=opts.TitleOpts(title=item_id),toolbox_opts=opts.ToolboxOpts()) line.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=12,interval=0,rotate=-45)),title_opts=opts.TitleOpts(title=""),toolbox_opts=opts.ToolboxOpts()) #return {"Hello": "World"} xxx=''' <meta charset="UTF-8"> <script> setTimeout('location.href="/ping/{}"', 5000); </script> '''.format(item_id) y=line.render_embed() y=y.replace('<meta charset="UTF-8">',xxx) return HTMLResponse(content=y)
def line_html(self, title, key, val, color=None): line = Line(init_opts=opts.InitOpts(width="100%", height="300px")) line.set_global_opts( title_opts=opts.TitleOpts( title=title, title_textstyle_opts=opts.TextStyleOpts(color="black", font_size=14), pos_left="center", ), # 增添x,y轴以及内部的缩放 datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=100)], ) line.add_xaxis(key) line.add_yaxis( "", val, symbol=None, is_symbol_show=False, areastyle_opts=opts.AreaStyleOpts(opacity=0.5, color=color), linestyle_opts=opts.LineStyleOpts(opacity=0.2), markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="average", name="平均值"), opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="min", name="最小值"), opts.MarkLineItem(type_="average", name="平均值"), opts.MarkLineItem(type_="max", name="最大值"), opts.MarkLineItem(type_="min", name="最小值"), ] ), markline_opts=opts.MarkLineOpts( data=[ opts.MarkLineItem(type_="average", name="平均值"), opts.MarkLineItem(type_="max", name="最大值"), opts.MarkLineItem(type_="min", name="最小值") ] ), is_selected=True, is_smooth=True, is_hover_animation=True, ) return line.render_embed()
def plot_line(dfs): x_data = dfs['品牌'] y_data = dfs['Chg'] line = Line().set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=False), xaxis_opts=opts.AxisOpts(type_="category"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), )\ .add_xaxis(xaxis_data=x_data)\ .add_yaxis(series_name="Chg", y_axis=y_data, symbol="emptyCircle", is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False),) line.render("basic_line_chart.html") return line.render_embed()
def pyecharts(request): """dashboard view""" # 工单数量统计 chart_dao = ChartDao() data = chart_dao.workflow_by_date(30) today = date.today() one_month_before = today - relativedelta(days=+30) attr = chart_dao.get_date_list(one_month_before, today) _dict = {} for row in data['rows']: _dict[row[0]] = row[1] value = [_dict.get(day) if _dict.get(day) else 0 for day in attr] bar1 = Bar(init_opts=opts.InitOpts(width='600', height='380px')) bar1.add_xaxis(attr) bar1.add_yaxis("", value) # 工单按组统计 data = chart_dao.workflow_by_group(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie1 = Pie(init_opts=opts.InitOpts(width='600', height='380px')) pie1.set_global_opts(title_opts=opts.TitleOpts(title=''), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%", is_show=False)) pie1.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) pie1.add("", [list(z) for z in zip(attr, value)]) # 工单按人统计 data = chart_dao.workflow_by_user(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] bar2 = Bar(init_opts=opts.InitOpts(width='600', height='380px')) bar2.add_xaxis(attr) bar2.add_yaxis("", value) # SQL语句类型统计 data = chart_dao.syntax_type() attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie2 = Pie() pie2.set_global_opts(title_opts=opts.TitleOpts(title='SQL上线工单统计(类型)'), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%")) pie2.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) pie2.add("", [list(z) for z in zip(attr, value)]) # SQL查询统计(每日检索行数) attr = chart_dao.get_date_list(one_month_before, today) effect_data = chart_dao.querylog_effect_row_by_date(30) effect_dict = {} for row in effect_data['rows']: effect_dict[row[0]] = int(row[1]) effect_value = [ effect_dict.get(day) if effect_dict.get(day) else 0 for day in attr ] count_data = chart_dao.querylog_count_by_date(30) count_dict = {} for row in count_data['rows']: count_dict[row[0]] = int(row[1]) count_value = [ count_dict.get(day) if count_dict.get(day) else 0 for day in attr ] line1 = Line(init_opts=opts.InitOpts(width='600', height='380px')) line1.set_global_opts(title_opts=opts.TitleOpts(title=''), legend_opts=opts.LegendOpts(selected_mode='single')) line1.add_xaxis(attr) line1.add_yaxis("检索行数", effect_value, is_smooth=True, markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="average")])) line1.add_yaxis("检索次数", count_value, is_smooth=True, markline_opts=opts.MarkLineOpts(data=[ opts.MarkLineItem(type_="max"), opts.MarkLineItem(type_="average") ])) # SQL查询统计(用户检索行数) data = chart_dao.querylog_effect_row_by_user(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie4 = Pie(init_opts=opts.InitOpts(width='600', height='380px')) pie4.set_global_opts(title_opts=opts.TitleOpts(title=''), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%", is_show=False)) pie4.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) pie4.add("", [list(z) for z in zip(attr, value)]) # SQL查询统计(DB检索行数) data = chart_dao.querylog_effect_row_by_db(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie5 = Pie(init_opts=opts.InitOpts(width='600', height='380px')) pie5.set_global_opts(title_opts=opts.TitleOpts(title=''), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%", is_show=False)) pie5.set_series_opts( label_opts=opts.LabelOpts(formatter="{b}: {c}", position="left")) pie5.add("", [list(z) for z in zip(attr, value)]) # 可视化展示页面 chart = { "bar1": bar1.render_embed(), "pie1": pie1.render_embed(), "bar2": bar2.render_embed(), "pie2": pie2.render_embed(), "line1": line1.render_embed(), "pie4": pie4.render_embed(), "pie5": pie5.render_embed(), } # 获取统计数据 dashboard_count_stats = { "sql_wf_cnt": SqlWorkflow.objects.count(), "query_wf_cnt": QueryPrivilegesApply.objects.count(), "user_cnt": Users.objects.count(), "ins_cnt": Instance.objects.count() } return render(request, "dashboard.html", { "chart": chart, "count_stats": dashboard_count_stats })
def MultipleLineCharts(datas): line = Line(init_opts=opts.InitOpts(width="100%")) line.add_xaxis(xaxis_data=[item[0] for item in datas[1][0][1]]) # 设置x轴数据 for data in datas[1]: line.add_yaxis( series_name=data[0], y_axis=[item[1] for item in data[1]], yaxis_index=0, is_smooth=True, is_symbol_show=False, is_connect_nones=True, ) # 设置y轴数据 line.set_global_opts( title_opts=opts.TitleOpts(title=datas['title']), tooltip_opts=opts.TooltipOpts(trigger="axis"), datazoom_opts=[ opts.DataZoomOpts(yaxis_index=0, range_start=0, range_end=100), opts.DataZoomOpts(type_="inside", yaxis_index=0), ], visualmap_opts=opts.VisualMapOpts( pos_top="10", pos_right="10", is_piecewise=True, pieces=[ { "gt": 0, "lte": 25, "color": "#096" }, { "gt": 25, "lte": 50, "color": "#ffde33" }, { "gt": 50, "lte": 75, "color": "#ff9933" }, { "gt": 75, "color": "#cc0033" }, ], out_of_range={"color": "#999"}, ), xaxis_opts=opts.AxisOpts(type_="category"), yaxis_opts=opts.AxisOpts( type_="value", name_location="start", min_=0, max_=100, is_scale=True, axistick_opts=opts.AxisTickOpts(is_inside=False), ), ) line.set_series_opts(markline_opts=opts.MarkLineOpts( data=[ { "yAxis": 25 }, { "yAxis": 50 }, { "yAxis": 75 }, ], label_opts=opts.LabelOpts(position="end"), )) # line.render()#渲染图表,默认文件名为render.html return line.render_embed()
def generate_line_html(rows, select=None): # 用散点图展示 line = Line( opts.InitOpts(height='700px', width='1424px', theme=ThemeType.LIGHT)) x = [] y1 = [] y2 = [] y3 = [] y4 = [] y5 = [] for row in rows: x.append(row['时间']) y3.append(row['低溢价率策略累积收益率']) y2.append(row['高收益率策略累积收益率']) y1.append(row['低余额+双低策略累积收益率']) y1.append(row['低溢价率+双低策略累积收益率']) # y4.append(row['可转债指数累积收益率']) # y5.append(row['沪深300累积收益率']) line.add_xaxis(x) line.add_yaxis("低溢价率策略", y3) line.add_yaxis("高收益率策略", y2) line.add_yaxis("低余额+双低策略", y1) line.add_yaxis("低溢价+双低策略", y1) # line.add_yaxis("可转债指数", y4) # line.add_yaxis("沪深300", y5) line.set_global_opts( title_opts=opts.TitleOpts(title="策略组合收益率", pos_left='center', pos_top=-5), tooltip_opts=opts.TooltipOpts( trigger='axis', formatter=JsCode( "function (params) {" "return '<table style=\"width:150px;\">'+" "'<tr ><td style=\"height:20px;background-color:white;border:0px\" colspan=2>'+ params[0].data[0] +'</td></tr>' +" "'<tr><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[1].color+'\">高收益率策略</td><td style=\"height:15px;background-color:white;border:0px\">' + params[1].value[1] + '%</td></tr>' +" "'<tr><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[2].color+'\">低溢价率策略</td><td style=\"height:15px;background-color:white;border:0px\">' + params[2].value[1] + '%</td></tr>' +" "'<tr ><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[0].color+'\">低余额+双低策略</td><td style=\"height:15px;background-color:white;border:0px\">' + params[3].value[1] + '%</td></tr>' +" "'<tr ><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[0].color+'\">低溢价率+双低策略</td><td style=\"height:15px;background-color:white;border:0px\">' + params[4].value[1] + '%</td></tr>' +" "'<tr><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[3].color+'\">可转债指数</td><td style=\"height:15px;background-color:white;border:0px\">' + params[5].value[1] + '%</td></tr>' +" "'<tr><td style=\"height:15px;background-color:white;border:0px;text-align: left;color:'+params[4].color+'\">沪深300</td><td style=\"height:15px;background-color:white;border:0px\">' + params[6].value[1] + '%</td></tr>' +" "'</table>';}")), legend_opts=opts.LegendOpts(pos_top=50, # selected_mode='single' ), datazoom_opts={ 'start': 0, 'end': 100 }, toolbox_opts=opts.ToolboxOpts(feature={ 'dataZoom': {}, }), # visualmap_opts=opts.VisualMapOpts( # type_="color", max_=150, min_=20, dimension=1 # ), xaxis_opts=opts.AxisOpts( # data=None, type_='time', name='时间', name_gap=30, is_scale=True, name_location='middle', splitline_opts=opts.SplitLineOpts(is_show=False), # axislabel_opts=opts.LabelOpts(formatter="{value}"), #echarts.format.formatTime('yy-MM-dd', value*1000) axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow'])), yaxis_opts=opts.AxisOpts( type_='value', name='收益率(%)', name_rotate=90, name_gap=55, name_location='middle', is_scale=True, axislabel_opts=opts.LabelOpts(formatter='{value}%'), splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow']))) line.set_series_opts( symbol='none', smooth=False, label_opts=opts.LabelOpts(is_show=False), ) line_html = line.render_embed('template.html', env) return line_html
def generate_line_html2(rows, select=None): line = Line( opts.InitOpts(height='500px', width='1424px', theme=ThemeType.LIGHT)) x = [] y1 = [] y2 = [] min_y = 10000 max_y = 0 for row in rows: x.append(row['date']) mid_price = row['mid_price'] avg_premium = row['avg_premium'] if mid_price > max_y: max_y = mid_price elif mid_price < min_y: min_y = mid_price y1.append(mid_price) y2.append(avg_premium) delta = max_y - min_y interval = round(delta / 5, 2) star_up1 = round(min_y + interval * 1, 2) star_up2 = round(min_y + interval * 2, 2) star_up3 = round(min_y + interval * 3, 2) star_up4 = round(min_y + interval * 4, 2) line.add_xaxis(x) line.extend_axis( yaxis=opts.AxisOpts(type_='value', name='溢价率平均值(%)', name_rotate=90, name_gap=55, name_location='middle', is_scale=True, axislabel_opts=opts.LabelOpts( formatter='{value}%'), splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts( is_on_zero=False, symbol=['none', 'arrow']))) line.add_yaxis("价格中位数", y1, yaxis_index=0) line.add_yaxis("溢价率平均值", y2, yaxis_index=1) line.set_global_opts( title_opts=opts.TitleOpts(title="用价格中位数估值", pos_left='center', pos_top=-5), tooltip_opts=opts.TooltipOpts(trigger='axis', ), legend_opts=opts.LegendOpts( is_show=True, pos_top=20, # pos_bottom=-50, selected_mode='multiple'), datazoom_opts={ 'start': 0, 'end': 100 }, toolbox_opts=opts.ToolboxOpts(feature={ 'dataZoom': {}, }), xaxis_opts=opts.AxisOpts( # data=None, type_='time', name='时间', name_gap=30, is_scale=True, name_location='middle', splitline_opts=opts.SplitLineOpts(is_show=False), # axislabel_opts=opts.LabelOpts(formatter="{value}"), #echarts.format.formatTime('yy-MM-dd', value*1000) axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow'])), yaxis_opts=opts.AxisOpts( type_='value', name='价格中位数(元)', name_rotate=90, name_gap=55, name_location='middle', is_scale=True, axislabel_opts=opts.LabelOpts(formatter='{value}元'), splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow'])), visualmap_opts=opts.VisualMapOpts(is_show=True, type_='color', pos_top='50', pos_left='5', min_=min_y, max_=max_y, is_piecewise=True, split_number=5, series_index=0, pieces=[ { 'min': min_y, 'max': star_up1, 'color': '#93CE07', 'label': '★★★★★' }, { 'min': star_up1, 'max': star_up2, 'color': '#FBDB0F', 'label': '★★★★' }, { 'min': star_up2, 'max': star_up3, 'color': '#FC7D02', 'label': '★★★' }, { 'min': star_up3, 'max': star_up4, 'color': '#FD0100', 'label': '★★' }, { 'min': star_up4, 'max': max_y, 'color': '#AC3B2A', 'label': '★' }, ]), ) line.set_colors(['lightcoral', 'lightskyblue']) line.set_series_opts( symbol='none', smooth=False, linestyle_opts=opts.LineStyleOpts(width=2, ), label_opts=opts.LabelOpts(is_show=False), markline_opts=opts.MarkLineOpts( is_silent=True, symbol='none', label_opts=opts.LabelOpts( position='end', is_show=False, formatter=JsCode("function (params){return params.name}")), linestyle_opts=opts.LineStyleOpts( color='#333', type_='dashed', ), data=[ opts.MarkLineItem(y=min_y, name='0%'), opts.MarkLineItem(y=star_up1, name='20%'), opts.MarkLineItem(y=star_up2, name='40%'), opts.MarkLineItem(y=star_up3, name='60%'), opts.MarkLineItem(y=star_up4, name='80%'), opts.MarkLineItem(y=max_y, name='100%'), ]), ) line_html = line.render_embed('template.html', env) return line_html
def generate_line_html(rows, period, start, end, bond_num, line_names=[], title=None, max_price=None, max_double_low=None): # 用散点图展示 line = Line( opts.InitOpts(height='700px', width='1424px', theme=ThemeType.LIGHT)) x, data = get_line_data(rows, line_names) # i = 0 # y1_max = None # y1_min = None # y2_max = None # y2_min = None # for e in x: # if i == y1_start: # y1_max = e # elif i == y1_end: # y1_min = e # # if i == y2_start: # y2_max = e # elif i == y2_end: # y2_min = e # i += 1 line.add_xaxis(x) for d in data: line.add_yaxis(d[0], d[1]) line.set_global_opts( title_opts=opts.TitleOpts( title=title if title is not None else "各种轮动策略回测结果", subtitle=get_subtitle(bond_num, end, period, start, max_price, max_double_low), pos_left='center'), tooltip_opts=opts.TooltipOpts(trigger='axis', ), legend_opts=opts.LegendOpts(pos_top=50, pos_left=160, orient='vertical' # selected_mode='single' ), datazoom_opts={ 'start': 0, 'end': 100 }, toolbox_opts=opts.ToolboxOpts(feature={ 'dataZoom': {}, }), # visualmap_opts=opts.VisualMapOpts( # type_="color", max_=150, min_=20, dimension=1 # ), xaxis_opts=opts.AxisOpts( # data=None, type_='time', name='时间', name_gap=30, is_scale=True, name_location='middle', splitline_opts=opts.SplitLineOpts(is_show=False), # axislabel_opts=opts.LabelOpts(formatter="{value}"), #echarts.format.formatTime('yy-MM-dd', value*1000) axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow'])), yaxis_opts=opts.AxisOpts( type_='value', name='收益率(%)', name_rotate=90, name_gap=55, name_location='middle', is_scale=True, axislabel_opts=opts.LabelOpts(formatter='{value}%'), splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_on_zero=False, symbol=['none', 'arrow']))) line.set_series_opts( symbol='none', smooth=False, label_opts=opts.LabelOpts(is_show=False), # markarea_opts=opts.MarkAreaOpts( # is_silent=False, # data=[ # opts.MarkAreaItem( # name="" + str(y1_mdd) + "%", # x=(y1_max, y1_min), # label_opts=opts.LabelOpts(is_show=True, color="#DCA3A2"), # itemstyle_opts=opts.ItemStyleOpts(color="#DCA3A2", opacity=0.5), # ), # opts.MarkAreaItem( # name="" + str(y2_mdd) + "%", # x=(y2_max, y2_min), # label_opts=opts.LabelOpts(is_show=True, color="#b0fca2"), # itemstyle_opts=opts.ItemStyleOpts(color="#b0fca2", opacity=0.5), # ) # ] # ) ) line_html = line.render_embed('template.html', env) return "<br/>" + line_html