コード例 #1
0
def timelineChart(df):
    x = Faker.choose()
    tl = Timeline()
    for i in range(2015, 2020):
        bar = (
            Bar()
            .add_xaxis(x)
            .add_yaxis("商家A", Faker.values())
            .add_yaxis("商家B", Faker.values())
            .set_global_opts(
                title_opts=opts.TitleOpts("某商店{}年营业额 - With Graphic 组件".format(i)),
                toolbox_opts=opts.ToolboxOpts(), brush_opts=opts.BrushOpts(),
                graphic_opts=[
                    opts.GraphicGroup(
                        graphic_item=opts.GraphicItem(
                            rotation=JsCode("Math.PI / 4"),
                            bounding="raw",
                            right=100,
                            bottom=110,
                            z=100,
                        ),
                        children=[
                            opts.GraphicRect(
                                graphic_item=opts.GraphicItem(
                                    left="center", top="center", z=100
                                ),
                                graphic_shape_opts=opts.GraphicShapeOpts(
                                    width=400, height=50
                                ),
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="rgba(0,0,0,0.3)"
                                ),
                            ),
                            opts.GraphicText(
                                graphic_item=opts.GraphicItem(
                                    left="center", top="center", z=100
                                ),
                                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                    text="某商店{}年营业额".format(i),
                                    font="bold 26px Microsoft YaHei",
                                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                        fill="#fff"
                                    ),
                                ),
                            ),
                        ],
                    )
                ],
            )
        )
        tl.add(bar, "{}年".format(i)) 
        return tl  
コード例 #2
0
def bar_graphic_rect_text_two_component() -> Bar:
    c = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values())
        .add_yaxis("商家B", Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 2 组件示例"),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(left="50%", top="15%"),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100, left="center", top="middle"
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=190, height=90
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="middle", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text=JsCode(
                                    "['横轴表示数据类别',"
                                    "'纵轴表示数值的值',"
                                    "'这个文本块可以放在图中各',"
                                    "'种位置'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
コード例 #3
0
def bar_graphic_rect_text_one_component() -> Bar:
    c = (
        Bar()
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values())
        .add_yaxis("商家B", Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 1 组件示例"),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        rotation=JsCode("Math.PI / 4"),
                        bounding="raw",
                        right=110,
                        bottom=110,
                        z=100,
                    ),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=50
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="rgba(0,0,0,0.3)"
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text="pyecharts bar chart",
                                font="bold 26px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#fff"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
コード例 #4
0
ファイル: test_timeline.py プロジェクト: zjuitc/pyecharts
 def test_timeline_graphic(self):
     self.tl.add_schema(
         graphic_opts=[
             opts.GraphicGroup(
                 graphic_item=opts.GraphicItem(
                     rotation=JsCode("Math.PI / 4"),
                     bounding="raw",
                     right=110,
                     bottom=110,
                     z=100,
                 ),
                 children=[
                     opts.GraphicRect(
                         graphic_item=opts.GraphicItem(
                             left="center", top="center", z=100
                         ),
                         graphic_shape_opts=opts.GraphicShapeOpts(
                             width=400, height=50
                         ),
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                             fill="rgba(0,0,0,0.3)"
                         ),
                     ),
                     opts.GraphicText(
                         graphic_item=opts.GraphicItem(
                             left="center", top="center", z=100
                         ),
                         graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                             text="pyecharts bar chart",
                             font="bold 26px Microsoft YaHei",
                             graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                 fill="#fff"
                             ),
                         ),
                     ),
                 ],
             )
         ]
     )
     eq_(
         type(opts.GraphicGroup()),
         type(self.tl.options.get("baseOption").get("timeline").get("graphic")[0]),
     )
コード例 #5
0
def syz_mark():
    """私人标记"""
    graphic_opts = [
        opts.GraphicGroup(
            graphic_item=opts.GraphicItem(
                rotation=JsCode("Math.PI / 4"),
                bounding="raw",
                right=80,
                bottom=80,
                z=100,
            ),
            children=[
                opts.GraphicRect(
                    graphic_item=opts.GraphicItem(
                        left="center", top="center", z=100
                    ),
                    graphic_shape_opts=opts.GraphicShapeOpts(
                        width=400, height=50
                    ),
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="rgba(0,0,0,0.3)"
                    ),
                ),
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center", top="center", z=100
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        text="云博",
                        font="bold 26px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#fff"
                        ),
                    ),
                ),
            ],
        )
    ]
    return graphic_opts
コード例 #6
0
ファイル: Extremum.py プロジェクト: jiangqicd/DT2VIS
def find_extremum_render(x,y,x_name,y_name,query,operator,answer):
    x=list(map(str,x))
    y=list(map(float,y))
    makepoint=[]
    makeline=[]
    if operator=="MAX":
        makepoint.append(opts.MarkPointItem(type_="max",value="max",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6)))
        makeline.append(opts.MarkPointItem(type_="max", value="max"))
    else:
        makepoint.append(opts.MarkPointItem(type_="min", value="min", itemstyle_opts=opts.ItemStyleOpts(opacity=0.6)))
        makeline.append(opts.MarkPointItem(type_="min", value="min"))
    line=Line()
    line.add_xaxis(x)
    line.add_yaxis(
        y_name,
        y_axis=y,
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size='100%',
        markpoint_opts=opts.MarkPointOpts(
            data=makepoint,
            symbol_size=50,
            label_opts=opts.LabelOpts(formatter=operator)
        ),
        markline_opts=opts.MarkLineOpts(
            data=makeline,
            label_opts=opts.LabelOpts(formatter=operator+":{c}")
        )
    )

    line.set_global_opts(
        datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                       opts.DataZoomOpts(type_="inside")],
        yaxis_opts=opts.AxisOpts(min_=int(min(y)-(max(y)-min(y))/10),name=y_name,axislabel_opts=opts.LabelOpts(font_size="100%"),name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        legend_opts=opts.LegendOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40,font_size='100%'),name=x_name,name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        graphic_opts=[opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",
                z=100,
            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333"
                )
            )
        )]
    )
    grid = Grid( init_opts=opts.InitOpts(
        width="100%",
        height="100%",
                            renderer= globals.RenderType.SVG,
                            ))
    grid.add(line,  grid_opts={'left':'20%','bottom':'34%'})
    # grid1=Grid()
    # grid1.add(line,  grid_opts={'left':'20%','bottom':'34%'})
    # grid1.render("MAX.html")
    option1=grid.dump_options_with_quotes()
    option1=json.loads(option1)
    option={"option":[option1],"query":query}
    return option
コード例 #7
0
ファイル: 06LineChart.py プロジェクト: TedLau/NeuralNetwork
                    top='middle',
                    z=100,
                    scale=[1.5, 1.5]  # 缩放
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    text=
                    "直到{},\n全国的新冠状肺炎病毒的相关信息为:\n死亡病例为{}例,\n治愈病例为{}例,\n确诊病例为{}例,\n疑似病例为{}例,专家呼吁:\n广大积极配置国家政策进行疫情防疫工作"
                    .format(his.loc[0, '时间'], his.loc[0, '死亡数'],
                            his.loc[0, '治愈数'], his.loc[0, '确诊数'],
                            his.loc[0, '疑似数']),
                    font="15px Microsoft YaHei",
                    text_align='left',
                    text_vertical_align='middle',  # 垂直对齐方式 默认None
                    # 图形配置
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill='#ffdf22',
                        line_width=1.2,
                    )))
        ]))
# 添加系列配置
bar.set_series_opts(
    label_opts=opts.LabelOpts(is_show=True),  # 设置开启label
)

# 绘制折线图
line1 = Line()

# 添加数据
line1.add_xaxis(time_data)
line1.add_yaxis(series_name='确诊数',
                y_axis=diag_num,
                color='#4b0101',
コード例 #8
0
def find_distribution_render(x,Y,x_name,query,table_path,answer):
    Max=0
    y=[]
    data=[]
    label=[]
    boxplot = Boxplot()
    boxplot.add_xaxis(xaxis_data=label)
    for i in range(len(Y)):
        data.append(Y[i][1])
        label.append(Y[i][0])
        # boxplot.add_yaxis(series_name=Y[i][0],y_axis=boxplot.prepare_data(data))
        for j in Y[i][1]:
            y.append(j)
    boxplot.add_yaxis(series_name="", y_axis=boxplot.prepare_data(data))
    boxplot.set_global_opts(
        yaxis_opts=opts.AxisOpts(name="Distribution",axislabel_opts=opts.LabelOpts(font_size="100%"),name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        legend_opts=opts.LegendOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40,interval=0,font_size='100%'),name="Category",name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        graphic_opts=[opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",
                z=100,
            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n'+"\n" + 'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333"
                )
            )
        )]
    )

    bar=Bar({"theme": ThemeType.MACARONS})
    bar.add_xaxis(xaxis_data=x)
    for i in range(len(Y)):
        max_index, max_number = max(enumerate(Y[i][1]), key=operator.itemgetter(1))
        min_index, min_number = min(enumerate(Y[i][1]), key=operator.itemgetter(1))
        if max_number>Max:
            Max=max_number
        bar.add_yaxis(Y[i][0],label_opts=opts.LabelOpts(is_show=False),y_axis=Y[i][1],markpoint_opts=opts.MarkPointOpts(
            data=[opts.MarkPointItem(coord=[max_index,max_number*1.01],value="MAX",name="最大值",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6)),opts.MarkPointItem(coord=[min_index,min_number*1.05],value="MIN",name="最小值",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6))]
        ),
                      markline_opts=opts.MarkLineOpts(
                          data=[opts.MarkLineItem(type_="average",name="平均值")]
                      ))
    bar.set_global_opts(
        datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                       opts.DataZoomOpts(type_="inside")],
        yaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(font_size="100%"),
                                 name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40, interval=0, font_size='100%'),
                                 name=x_name, name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
        graphic_opts=[opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",

            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n' + "\n"+'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333"
                )
            )
        )]
    )
    grid = Grid( init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer= globals.RenderType.SVG,))
    grid.add(boxplot,  grid_opts={'left':'20%','bottom':'34%'})
    grid1 = Grid( init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer= globals.RenderType.SVG,))
    grid1.add(bar,grid_opts={'left':'20%','bottom':'34%'})
    option1=grid.dump_options_with_quotes()
    option1=json.loads(option1)
    option2=grid1.dump_options_with_quotes()
    option2=json.loads(option2)
    option={"option":[option1,option2],"query":query}
    return option
コード例 #9
0
ファイル: Trend.py プロジェクト: jiangqicd/DT2VIS
def TREND_render(x,y,z,y_up,y_down,max_index,min_index,x_name,y_name,query,answer):
    x=list(map(str,x))
    y=list(map(float,y))
    bar = (
        Bar()
            .add_xaxis(xaxis_data=x)
            .add_yaxis(
            series_name="increase_value",
            y_axis=y_up,
            markpoint_opts=opts.MarkPointOpts(
            data=[opts.MarkPointItem(type_='max')]
            ),

        )
        #     .add_yaxis(series_name="increase", yaxis_data=y_up, stack="GDP",markpoint_opts=opts.MarkPointOpts(
        #     data=[opts.MarkPointItem(name=x[max_index], coord=[x[max_index], y[max_index]+y_up[max_index]+z[max_index]], value="Max")]
        # ),)
            .add_yaxis(series_name="decrease_value", y_axis=y_down, stack="GDP",markpoint_opts=opts.MarkPointOpts(
            data=[opts.MarkPointItem(type_='max')]
        ),)
            .set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
            yaxis_opts=opts.AxisOpts(
                name=y_name,
                type_="value",
                axislabel_opts=opts.LabelOpts(formatter="{value}"),
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
            xaxis_opts=opts.AxisOpts(name=x_name),
            graphic_opts=[opts.GraphicText(
            graphic_item=opts.GraphicItem(
              left="center",
              top="bottom",

        ),
          graphic_textstyle_opts=opts.GraphicTextStyleOpts(
            # 可以通过jsCode添加js代码,也可以直接用字符串
            text=['\n'+"Q:"+' '+query+'\n'+"\n"+'A:'+' '+answer],
            font="14px Microsoft YaHei",
            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                fill="#333"
            )
        )
    )]
        )
    )

    line = (
        Line()
            .add_xaxis(xaxis_data=x)
            .add_yaxis(
            series_name='food',
            yaxis_index=0,
            y_axis=y,
            label_opts=opts.LabelOpts(is_show=True),
            # markpoint_opts=opts.MarkPointOpts(
            #     data=[opts.MarkPointItem(type_='max', value='Max'),opts.MarkPointItem(type_='min',value='Max')],
            # ),
        )

        .set_global_opts(legend_opts=opts.LegendOpts(is_show=False),  )
    )
    # line.overlap(bar).render("TREND.html")
    grid = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
    grid.add(bar.overlap(line), grid_opts={'left': '20%', 'bottom': '34%'})
    option1 = grid.dump_options_with_quotes()
    option1 = json.loads(option1)
    option = {"option": [option1], "query": query}
    return option
コード例 #10
0
def get_year_chart(date):
    data = pd.read_csv('./china/{}.csv'.format(date))
    df_clear = data.drop(data[(data['地区'] == '香港')].index)
    df_clear1 = df_clear.drop(df_clear[df_clear['新增确诊'] == 0].index)
    df_clear2 = df_clear.drop(df_clear[df_clear['现有确诊'] == 0].index)
    name = list(df_clear['地区'])
    nowConfirm = list(df_clear1['新增确诊'])
    confirm = list(df_clear2['现有确诊'])
    heal = list(df_clear['治愈'])
    dead = list(df_clear['死亡'])
    map_chart = (Map().add(
        series_name="",
        data_pair=[list(z) for z in zip(name, confirm)],
        label_opts=opts.LabelOpts(is_show=False),
        is_map_symbol_show=False,
    ).set_global_opts(
        title_opts=opts.TitleOpts(
            title="现有疫情和新增疫情",
            subtitle="中国",
            pos_left="center",
            pos_top="top",
            title_textstyle_opts=opts.TextStyleOpts(
                font_size=25, color="rgba(255,255,255, 0.9)"),
        ),
        tooltip_opts=opts.TooltipOpts(is_show=True, ),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["高风险地区", "低风险地区"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=0,
            max_=100,
        ),
    ))

    bar = (Bar().add_xaxis(xaxis_data=name).add_yaxis(
        series_name="",
        yaxis_index=1,
        y_axis=confirm,
        label_opts=opts.LabelOpts(is_show=True,
                                  position="right",
                                  formatter="{b}: {c}"),
    ).reversal_axis().set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["高风险地区", "低风险地区"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=0,
            max_=100,
        ),
        graphic_opts=[
            opts.GraphicGroup(
                graphic_item=opts.GraphicItem(
                    bounding="raw",
                    right=110,
                    bottom=11,
                    z=100,
                ),
                children=[
                    opts.GraphicRect(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                                 height=50),
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="rgba(0,0,0,0.3)"),
                    ),
                    opts.GraphicText(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                            text=date,
                            font="bold 26px Microsoft YaHei",
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff"),
                        ),
                    ),
                ],
            )
        ],
    ))

    pie = (Pie().add(
        series_name="",
        data_pair=[list(z) for z in zip(name, nowConfirm)],
        radius=["12%", "20%"],
        center=["75%", "85%"],
        itemstyle_opts=opts.ItemStyleOpts(border_width=1,
                                          border_color="rgba(0,0,0,0.3)"),
    ).set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
        legend_opts=opts.LegendOpts(is_show=False),
    ))

    grid_chart = (Grid().add(
        bar,
        grid_opts=opts.GridOpts(pos_left="10",
                                pos_right="45%",
                                pos_top="70%",
                                pos_bottom="5"),
    ).add(pie, grid_opts=opts.GridOpts()).add(map_chart,
                                              grid_opts=opts.GridOpts()))

    return grid_chart
コード例 #11
0
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 文本内容
                    text=
                    """直到{},\n全国的新冠状病毒的相关信息为:\n死亡数例数为{}列\n治愈数例数为{}例\n疑似数例数为{}例\n确诊数例数为{}例"""
                    .format(history_data.loc[0, '时间'], history_data.loc[0,
                                                                        '死亡数'],
                            history_data.loc[0, '治愈数'],
                            history_data.loc[0,
                                             '疑似数'], history_data.loc[0,
                                                                      '确诊数']),
                    font='13px Microsoft YaHei',  # 字体
                    text_align='left',  # 水平对其方式: 左对齐
                    text_vertical_align='middle',  # 垂直对其方式:居中
                    # 图形化基本设置
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill='#ffdf22'  # 设置颜色
                    )))
        ]))

# 给line增加系列配置
line.set_series_opts(
    #
    label_opts=opts.LabelOpts(is_show=False))

# 层叠
all_chart = bar.overlap(line)

# 组合柱状图、折线图
# 并行多图
grid = Grid(
    # 初始化设置
コード例 #12
0
def find_proportion_render(x, y, z, part_name, main_name, query, table_path,
                           answer):
    x = list(map(str, x))
    y = list(map(float, y))
    z = list(map(float, z))
    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff']
    y_part = []
    y_main = []
    for i in range(len(y)):
        percentage = y[i] / z[i] * 100
        percentage = str(percentage).split('.')[0] + '.' + str(
            percentage).split('.')[1][:2]
        y_part.append(
            opts.BarItem(
                name=x[i],
                value=y[i],
                label_opts=opts.LabelOpts(position="insideTop",
                                          formatter=str(percentage) + "%"),
                itemstyle_opts=opts.ItemStyleOpts(color=colorList[2])))
        y_main.append(opts.BarItem(
            name=x[i],
            value=z[i] - y[i],
        ))
    bar = Bar()
    bar.add_xaxis(x)
    bar.add_yaxis('',
                  y_axis=y_part,
                  stack='stack1',
                  label_opts=opts.LabelOpts(position="insideTop"),
                  itemstyle_opts=opts.ItemStyleOpts(color=colorList[2]),
                  tooltip_opts=opts.TooltipOpts(formatter=part_name + ':{c}')),
    bar.add_yaxis('',
                  y_axis=y_main,
                  stack='stack1',
                  label_opts=opts.LabelOpts(is_show=False),
                  color="gray",
                  tooltip_opts=opts.TooltipOpts(formatter=main_name + ':{c}'))
    bar.set_global_opts(
        datazoom_opts=[
            opts.DataZoomOpts(range_start=10, range_end=90),
            opts.DataZoomOpts(type_="inside")
        ],
        legend_opts=opts.LegendOpts(is_show=False),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer
                    ],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])
    bar.render("aggregation.html")
    grid = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid.add(bar, grid_opts={'left': '20%', 'bottom': '34%'})
    option1 = grid.dump_options_with_quotes()
    option1 = json.loads(option1)
    option = {"option": [option1], "query": query}
    return option
コード例 #13
0
 visualmap_opts=opts.VisualMapOpts(is_show=True, is_piecewise=True, pieces=[{"value": 1, "color": '#F95DBA', "label": '1个运营商支持', "symbol": 'circle', "symbolSize": 6}, {"value": 2, "color": '#A64DFF', "label": '2个运营商支持', "symbol": 'circle', "symbolSize": 6}, {"value": 3, "color": '#4E70F0', "label": '3个运营商支持', "symbol": 'circle', "symbolSize": 6}], pos_left='22%', pos_bottom='7%'),
 # 图表标题及副标题
 title_opts=opts.TitleOpts(title="目前提供5G商用网络的城市", subtitle='数据来源:电信、移动、联通官方发布', pos_left='center', pos_top='-1%', item_gap=5),
 # 隐藏图例
 legend_opts=opts.LegendOpts(is_show=False),
 # 添加多个文本
 graphic_opts=[
     opts.GraphicGroup(
         graphic_item=opts.GraphicItem(left='68%', top='52%', z=99),
         children=[
             opts.GraphicText(
                 graphic_item=opts.GraphicItem(left='68%', top='52%', z=100),
                 graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                     text='江浙沪共10\n个城市拥有\n商用5G网络',
                     font='bolder 14px Microsoft YaHei',
                     graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="black"))
             )
         ],
     ),
     opts.GraphicGroup(
         graphic_item=opts.GraphicItem(left='68%', top='61%', z=99),
         children=[
             opts.GraphicText(
                 graphic_item=opts.GraphicItem(left='68%', top='61%', z=100),
                 graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                     text='上海 杭州 南京\n苏州 无锡 南通 常州\n宁波 温州 嘉兴 绍兴',
                     font='lighter 12px Microsoft YaHei',
                     graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="black"))
             )
         ],
     ),
コード例 #14
0
 def draw_rose_piture(self,my_rose_data):
   total_position = 0
   for x in my_rose_data:
     total_position = total_position + x[1]
   #print(total_position)
   if os.path.isfile('pie_rosetype.html'):
      os.remove('.\pie_rosetype.html')
   c = (
       Pie()
       .add(
           "",
           my_rose_data,
           radius=["30%", "75%"],
           #center=["25%", "50%"],
           rosetype="radius",
           #label_opts=opts.LabelOpts(is_show=False),
       )
       #.add(
       #    "",
       #    my_rose_data,
       #    radius=["30%", "75%"],
       #    center=["75%", "50%"],
       #    rosetype="area",
       #)
       .set_global_opts(
           title_opts=opts.TitleOpts(title="Positions",pos_left="8%",pos_top="8%"),
           graphic_opts=[
               opts.GraphicGroup(
                   graphic_item=opts.GraphicItem(
                       # 控制整体的位置
                       right="15%",
                       bottom="5%",
                   ),
                   children=[
                       # opts.GraphicRect控制方框的显示
                       # 如果不需要方框,去掉该段即可
                       #opts.GraphicRect(
                       #    graphic_item=opts.GraphicItem(
                       #        z=100,
                       #        right="center",
                       #        bottom="middle",
                       #    ),
                       #    graphic_shape_opts=opts.GraphicShapeOpts(
                       #        width=120, height=70,
                       #    ),
                       #    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                       #        fill="#fff",
                       #        stroke="#555",
                       #        line_width=2,
                       #        shadow_blur=8,
                       #        shadow_offset_x=3,
                       #        shadow_offset_y=3,
                       #        shadow_color="rgba(144,238,144,0.3)",
                       #    )
                       #),
                       # opts.GraphicText控制文字的显示
                       opts.GraphicText(
                           graphic_item=opts.GraphicItem(
                               left="center",
                               top="middle",
                               z=100,
                           ),
                           graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                               # 可以通过jsCode添加js代码,也可以直接用字符串
                               text="Total:"+str(total_position)+"%",
                               font="bolder 21px Microsoft YaHei",
                               graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                   fill="#C537B6"
                               )
                           )
                       )
                   ]
               )
           ]
       )
       .set_series_opts(label_opts=opts.LabelOpts(formatter="{b} {c}%"))
       .render("pie_rosetype.html")
   )
コード例 #15
0
def get_year_chart(data, all_data, year):
    map_data = [[[x["name"], x["value"]] for x in d["data"]] for d in data
                if d["time"] == year][0]
    map_temp_data = [[[x["name"], x["value"][0]] for x in d["data"]]
                     for d in all_data if d["time"] == year][0]

    min_data, max_data = (
        min([d[1][0] for d in map_data]),
        max([d[1][0] for d in map_data]),
    )

    #map = Map(init_opts=opts.InitOpts(width="1900px", height="900px", bg_color="#ADD8E6",page_title="4.15全球疫情确诊人数", theme="white"))

    map_chart = (
        Map().add(
            maptype="world",  #默认地图为中国地图,加上这个参数改成世界地图
            series_name="",
            data_pair=map_temp_data,
            label_opts=opts.LabelOpts(is_show=False),
            is_map_symbol_show=False,
            itemstyle_opts={
                "normal": {
                    "areaColor": "#323c48",
                    "borderColor": "#404a59"
                },
                "emphasis": {
                    "label": {
                        "show": Timeline
                    },
                    "areaColor": "rgba(255,255,255, 0.5)",
                },
            },
        ).set_global_opts(
            title_opts=opts.TitleOpts(
                title="世界各国现存确诊人数变化",
                subtitle="确诊人数单位:例",
                pos_left="center",
                pos_top="top",
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25, color="rgba(255,255,255, 0.9)"),
            ),
            tooltip_opts=opts.TooltipOpts(
                is_show=True,
                formatter=JsCode("""function(params) {
                    if ('value' in params.data) {
                        return params.data.value[2] + ': ' + params.data.value[0];
                    }
                }"""),
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="10",
                pos_top="center",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        ))

    bar_x_data = [x[0] for x in map_data]

    # 这里注释的部分会导致 label 和 value 与 饼图不一致
    # 使用下面的 List[Dict] 就可以解决这个问题了。
    # bar_y_data = [x[1][0] for x in map_data]
    bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data]
    bar = (Bar().add_xaxis(xaxis_data=bar_x_data).add_yaxis(
        series_name="",
        yaxis_index=1,
        y_axis=bar_y_data,
        label_opts=opts.LabelOpts(is_show=True,
                                  position="right",
                                  formatter="{b}: {c}"),
    ).reversal_axis().set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            is_calculable=True,
            dimension=0,
            pos_left="10",
            pos_top="center",
            range_text=["High", "Low"],
            range_color=["lightskyblue", "yellow", "orangered"],
            textstyle_opts=opts.TextStyleOpts(color="#ddd"),
            min_=min_data,
            max_=max_data,
        ),
        graphic_opts=[
            opts.GraphicGroup(
                graphic_item=opts.GraphicItem(
                    rotation=JsCode("Math.PI / 4"),
                    bounding="raw",
                    right=110,
                    bottom=110,
                    z=100,
                ),
                children=[
                    opts.GraphicRect(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                                 height=50),
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="rgba(0,0,0,0.3)"),
                    ),
                    opts.GraphicText(
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                            text=f"{str(year)}",
                            font="bold 26px Microsoft YaHei",
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff"),
                        ),
                    ),
                ],
            )
        ],
    ))

    pie_data = [[x[0], x[1][0]] for x in map_data]
    percent_sum = sum([x[1][1] for x in map_data])
    rest_value = 0
    for d in map_data:
        rest_percent = 100.0
        rest_percent = rest_percent - percent_sum
        if d[1][1] != 0:
            rest_value = d[1][0] * (rest_percent / d[1][1])
            break
    pie_data.append(["其他国家", rest_value])
    pie = (Pie().add(
        series_name="",
        data_pair=pie_data,
        radius=["12%", "20%"],
        center=["75%", "85%"],
        itemstyle_opts=opts.ItemStyleOpts(border_width=1,
                                          border_color="rgba(0,0,0,0.3)"),
    ).set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
        legend_opts=opts.LegendOpts(is_show=False),
    ))

    grid_chart = (Grid().add(
        bar,
        grid_opts=opts.GridOpts(pos_left="10",
                                pos_right="45%",
                                pos_top="70%",
                                pos_bottom="5"),
    ).add(pie, grid_opts=opts.GridOpts()).add(map_chart,
                                              grid_opts=opts.GridOpts()))

    return grid_chart
コード例 #16
0
def line_base() -> Line:
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="5%",
                        top="10%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=800, height=400,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据: ',"
                                    "'  ',"
                                    "'2007-2009年中,新加坡、马耳他、冰岛以及哥斯达黎加等国,位列世界高科技出口的前列,高科技出口数量远超其他国家。',"
                                    "'  ',"
                                    "'  ',"
                                    "'2010-2014年中,随着各国家的发展,越来越多的国家开始出口高科技,比如马来西亚,格陵兰岛,尼日尔、哈萨克斯坦等国家,',"
                                    "'  ',"
                                    "'开始增加自己的高科技出口,在世界高科技出口中开始崭露头角。',"
                                    "'  ',"
                                    "'  ',"
                                    "'2015-2018年中,高科技出口的前列国家变化很大,有塞舌尔,阿拉伯联合酋长国,百慕大群岛等国的昙花一现,',"
                                    "'  ',"
                                    "'也有帕劳共和国以及菲律宾等国经久不衰,世界高科技出口的国家朝着多极化方向发展。',"
                                    "'  ',"
                                    "'  ',"
                                    "'表明近十几年来,世界各国都认识到了高科技出口的重要性,',"
                                    "'  ',"
                                    "'  ',"
                                    "'开始利用先进的技术基础设施、商业政策环境以及获得商业融资渠道的便利性等因素,',"
                                    "'  ',"
                                    "'出口本国的高科技产品,以增加国家在世界上的竞争力。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )
    return bar
コード例 #17
0
def grid_horizontal() -> Grid:
    bar0 = (
        Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
            .add_xaxis(['高收入国家', '低收入国家', '中低等收入国家', '中高等收入国家'])
            .add_yaxis("Income_Group", [high, low, middle_low, middle_high])
            .set_global_opts(title_opts=opts.TitleOpts(title="Income_Group", subtitle="2019", pos_left="2%"),
                             legend_opts=opts.LegendOpts(pos_left="20%"))
    )
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="52%",
                        top="7%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=415, height=440,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['世界银行是按人均国民总收入对世界各国经济发展水平进行分组。 ',"
                                    "'通常把世界各国分成四组,',"
                                    "'即低收入国家、中等偏下收入国家、',"
                                    "'中等偏上收入国家和高收入国家。',"
                                    "'但以上标准不是固定不变的,而是随着经济的发展不断进行调整。',"
                                    "'中等偏下收入国家和中等偏上收入国家合称为中等收入国家。',"
                                    "'  ',"
                                    "'按世界银行(World Bank)公布的数据,',"
                                    "'2018年的最新收入分组标准为:',"
                                    "'人均国民总收入低于995美元为低收入国家,',"
                                    "'在996至3895美元之间为中等偏下收入国家,',"
                                    "'在3896至12055元之间为中等偏上收入国家,',"
                                    "'高于12055美元为高收入国家。',"
                                    "'  ',"
                                    "'此图所统计的217个经济体中,',"
                                    "'高收入国家79个,低收入国家31个,',"
                                    "'中低等收入国家47个,中高等收入国家60个。',"
                                    "'由此看出,',"
                                    "'全球大多数国家收入水平都处于中等收入水平或者高收入水平,',"
                                    "'只有少部分国家处于低收入水平。',"
                                    "'  ',"
                                    "'美国、日本、英法德以及韩国等为高收入国家;',"
                                    "'俄罗斯、巴西、中国、土耳其、马来西亚等',"
                                    "'目前是中高等收入国家;',"
                                    "'印度、巴基斯坦、越南、菲律宾等国为中低收入国家;',"
                                    "'阿富汗、坦桑尼亚、柬埔寨、尼泊尔、埃塞俄比亚等',"
                                    "'为低收入国家。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )

    grid = (
        Grid()
            .add(bar, grid_opts=opts.GridOpts(pos_left="55%"))
            .add(bar0, grid_opts=opts.GridOpts(pos_right="55%"))
    )
    return grid
コード例 #18
0
def bar_base() -> Line:
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="5%",
                        top="10%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=800, height=400,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据, ',"
                                    "'  ',"
                                    "'亚洲地区在近十几年来,有着越来越多的国家增加高科技的出口,并且大体上呈现逐年增加的趋势。',"
                                    "'  ',"
                                    "'  ',"
                                    "'欧洲地区,随着大多数经济体的衰落或者停滞不前,',"
                                    "'  ',"
                                    "'欧洲各地的高科技出口都难以取得进展,但仍然处于世界高科技出口的中上行列。',"
                                    "'  ',"
                                    "'  ',"
                                    "'北美洲,得益于美国加拿大等强国,一直都保持的稳定的高科技出口。',"
                                    "'  ',"
                                    "'  ',"
                                    "'南美洲,在金融危机之后,开始出现了高科技出口,并且也是大体上呈现高科技出口国家逐年增加的趋势;',"
                                    "'  ',"
                                    "'  ',"
                                    "'非洲地区是目前世界上高科技出口水平较弱的地区,近十几年来无明显变化趋势,处于世界高科技出口的下游,水平有待加强。',"
                                    "'  ',"
                                    "'  ',"
                                    "'说明经济的不确定性对世界的发展状况息息相关,国际政治格局和贸易关系迅速变化导致全球市场高度不确定,',"
                                    "'  ',"
                                    "'在这样的十几年里,制度的质量似乎是促进繁荣的重要因素。',"
                                    "'  ',"
                                    "'强有力的制度框架为企业投资和创新提供了稳定性,确保了公民更高的生活质量。'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )
    return bar
コード例 #19
0
def grid_horizontal1() -> Grid:
    bar1 = (
        Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
            .add_xaxis(['南亚', '撒哈拉以南非洲地区(不包括高收入)', '欧洲与中亚地区(不包括高收入)',
                        '拉丁美洲与加勒比海地区(不包括高收入)', '东亚与太平洋地区(不包括高收入)', '中东与北非地区(不包括高收入)'])
            .add_yaxis("Region",
                       [Region.count('南亚'),
                        Region.count('撒哈拉以南非洲地区(不包括高收入)'),
                        Region.count('欧洲与中亚地区(不包括高收入)'),
                        Region.count('拉丁美洲与加勒比海地区(不包括高收入)'),
                        Region.count('东亚与太平洋地区(不包括高收入)'),
                        Region.count('中东与北非地区(不包括高收入)')])
            .set_global_opts(title_opts=opts.TitleOpts(title="Region", subtitle="2019", pos_left="2%"),
                             legend_opts=opts.LegendOpts(pos_left="20%"))
    )
    bar = (
        Bar()

            .set_global_opts(
            title_opts=opts.TitleOpts(title=""),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        # 控制整体的位置
                        left="52%",
                        top="7%",
                    ),
                    children=[

                        # opts.GraphicRect控制方框的显示
                        # 如果不需要方框,去掉该段即可
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                z=100,
                                left="center",
                                top="middle",
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=440,
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="#fff",
                                stroke="#555",
                                line_width=2,
                                shadow_blur=8,
                                shadow_offset_x=3,
                                shadow_offset_y=3,
                                shadow_color="rgba(0,0,0,0.3)",
                            )
                        ),
                        # opts.GraphicText控制文字的显示
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center",
                                top="middle",
                                z=100,
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                # 可以通过jsCode添加js代码,也可以直接用字符串
                                text=JsCode(
                                    "['根据世界银行(World Bank)统计数据, ',"
                                    "'南亚有8个国家、',"
                                    "'撒哈拉以南非洲地区有48个国家、',"
                                    "'欧洲与中亚地区有58个国家、',"
                                    "'拉丁美洲与加勒比海地区有42个国家、',"
                                    "'东亚与太平洋地区有37个国家、',"
                                    "'中东与北非地区有21个国家。',"
                                    "'  ',"
                                    "'此图除去了世界高收入国家,',"
                                    "'南亚8个国家、撒哈拉以南非洲地区47个国家、',"
                                    "'欧洲与中亚地区有21个国家、',"
                                    "'拉丁美洲与加勒比海地区有25个国家、',"
                                    "'东亚与太平洋地区有24个国家、',"
                                    "'中东与北非地区有13个国家不属于高收入国家。',"
                                    "'  ',"
                                    "'各地区高收入国家占比分别为(四舍五入取整):',"
                                    "'南亚0%、撒哈拉以南非洲地区98%、',"
                                    "'欧洲与中亚地区36%、',"
                                    "'拉丁美洲与加勒比海地区60%、',"
                                    "'东亚与太平洋地区65%、',"
                                    "'中东与北非地区62%',"
                                    "'  ',"
                                    "'收入与生活水平有一定联系。',"
                                    "'就各地区高收入国家占比,',"
                                    "'可对各地区生活水平做出以下排序(高到低):',"
                                    "'撒哈拉以南非洲地区>东亚与太平洋地区>',"
                                    "'中东与北非地区>拉丁美洲与加勒比海地区>',"
                                    "'欧洲与中亚地区>南亚'].join('\\n')"
                                ),
                                font="14px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#333"
                                )
                            )
                        )
                    ]
                )
            ],
        )
    )

    grid1 = (
        Grid()
            .add(bar, grid_opts=opts.GridOpts(pos_left="55%"))
            .add(bar1, grid_opts=opts.GridOpts(pos_right="55%"))
    )
    return grid1
コード例 #20
0
ファイル: Correlation.py プロジェクト: jiangqicd/DT2VIS
def find_correlation_render(attributes, data, pearsonr, query, table_path,
                            answer):
    dimensions = len(attributes)
    if dimensions == 2:
        data[0] = list(map(str, data[0]))
        data[1] = list(map(float, data[0]))
        l1_1 = Scatter()
        l1_1.add_xaxis(data[0])
        l1_1.add_yaxis("", data[1])
        l1_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[0]),
            yaxis_opts=opts.AxisOpts(name=attributes[1]),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        grid = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid.add(l1_1, grid_opts={'left': '15%', 'bottom': '34%'})
        option1 = grid.dump_options_with_quotes()
        option1 = json.loads(option1)
        option = {"option": [option1], "query": query}
        return option
    elif dimensions == 3:
        l1_1 = Scatter()
        data[0] = list(map(str, data[0]))
        data[1] = list(map(float, data[1]))
        data[2] = list(map(float, data[2]))
        l1_1.add_xaxis(data[0])
        l1_1.add_yaxis("", data[1])
        l1_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(
                name=attributes[0],
                axislabel_opts=opts.LabelOpts(rotate=50, interval=0),
                grid_index=0,
            ),
            yaxis_opts=opts.AxisOpts(
                name=attributes[1],
                grid_index=0,
            ),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        l1_2 = Scatter()
        l1_2.add_xaxis(data[0])
        l1_2.add_yaxis("", data[2])
        l1_2.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(
                name=attributes[0],
                axislabel_opts=opts.LabelOpts(rotate=50, interval=0),
                grid_index=1,
            ),
            yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=1),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                        z=100,
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        data[1] = list(map(str, data[1]))
        l2_1 = Scatter()
        l2_1.add_xaxis(data[1])
        l2_1.add_yaxis("", data[2])
        l2_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[0],
                                     axislabel_opts=opts.LabelOpts(rotate=50,
                                                                   interval=0),
                                     grid_index=2),
            yaxis_opts=opts.AxisOpts(name=attributes[1], grid_index=2),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        grid = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid.add(
            chart=l1_1,
            grid_opts=opts.GridOpts(pos_right="57%",
                                    pos_bottom="20%",
                                    pos_top="40%"),
            grid_index=0,
        )
        grid.add(
            chart=l1_2,
            grid_opts=opts.GridOpts(pos_left="57%",
                                    pos_bottom="20%",
                                    pos_top="40%"),
            grid_index=1,
        )
        grid.add(
            chart=l2_1,
            grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="60%"),
            grid_index=2,
        )
        option1 = grid.dump_options_with_quotes()
        option1 = json.loads(option1)
        option = {"option": [option1], "query": query}
        return option
    elif dimensions == 4:
        data[0] = list(map(str, data[0]))
        data[1] = list(map(float, data[1]))
        data[2] = list(map(float, data[2]))
        data[3] = list(map(float, data[3]))
        l1_1 = Scatter()
        l1_1.add_xaxis(data[0])
        l1_1.add_yaxis("", data[1])
        l1_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(
                name=attributes[0],
                axislabel_opts=opts.LabelOpts(rotate=50, interval=0),
                grid_index=0,
            ),
            yaxis_opts=opts.AxisOpts(
                name=attributes[1],
                grid_index=0,
            ),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        l1_2 = Scatter()
        l1_2.add_xaxis(data[0])
        l1_2.add_yaxis("", data[2])
        l1_2.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(
                name=attributes[0],
                axislabel_opts=opts.LabelOpts(rotate=50, interval=0),
                grid_index=1,
            ),
            yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=1),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        l2_1 = Scatter()
        l2_1.add_xaxis(data[0])
        l2_1.add_yaxis("", data[3])
        l2_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[0],
                                     axislabel_opts=opts.LabelOpts(rotate=50,
                                                                   interval=0),
                                     grid_index=2),
            yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=2),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        data[1] = list(map(str, data[1]))
        l2_2 = Scatter()
        l2_2.add_xaxis(data[1])
        l2_2.add_yaxis("", data[2])
        l2_2.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[1],
                                     axislabel_opts=opts.LabelOpts(rotate=50,
                                                                   interval=0),
                                     grid_index=3),
            yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=3),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        grid = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid.add(
            chart=l1_1,
            grid_opts=opts.GridOpts(pos_right="57%",
                                    pos_bottom="20%",
                                    pos_top="40%"),
            grid_index=0,
        )
        grid.add(
            chart=l1_2,
            grid_opts=opts.GridOpts(pos_left="57%",
                                    pos_bottom="20%",
                                    pos_top="40%"),
            grid_index=1,
        )
        grid.add(
            chart=l2_1,
            grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="60%"),
            grid_index=2,
        )
        grid.add(
            chart=l2_2,
            grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="60%"),
            grid_index=3,
        )
        r1_1 = Scatter()
        r1_1.add_xaxis(data[1])
        r1_1.add_yaxis("", data[3])
        r1_1.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[1],
                                     axislabel_opts=opts.LabelOpts(rotate=50,
                                                                   interval=0),
                                     grid_index=0),
            yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=0),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        data[2] = list(map(str, data[2]))
        r1_2 = Scatter()
        r1_2.add_xaxis(data[2])
        r1_2.add_yaxis("", data[3])
        r1_2.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(name=attributes[2],
                                     axislabel_opts=opts.LabelOpts(rotate=50,
                                                                   interval=0),
                                     grid_index=1),
            yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=1),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        grid1 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid1.add(
            chart=r1_1,
            grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="30%"),
            grid_index=0,
        )
        grid1.add(
            chart=r1_2,
            grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="30%"),
            grid_index=1,
        )
        option1 = grid.dump_options_with_quotes()
        option1 = json.loads(option1)
        option2 = grid1.dump_options_with_quotes()
        option2 = json.loads(option2)
        option = {"option": [option1, option2], "query": query}
        return option
コード例 #21
0
 title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 2 组件示例"),
 graphic_opts=[
     opts.GraphicGroup(
         graphic_item=opts.GraphicItem(left="50%", top="15%"),
         children=[
             opts.GraphicRect(
                 graphic_item=opts.GraphicItem(z=100,
                                               left="center",
                                               top="middle"),
                 graphic_shape_opts=opts.GraphicShapeOpts(width=190,
                                                          height=90),
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill="#fff",
                     stroke="#555",
                     line_width=2,
                     shadow_blur=8,
                     shadow_offset_x=3,
                     shadow_offset_y=3,
                     shadow_color="rgba(0,0,0,0.3)",
                 ),
             ),
             opts.GraphicText(
                 graphic_item=opts.GraphicItem(left="center",
                                               top="middle",
                                               z=100),
                 graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                     text=JsCode("['横轴表示数据类别',"
                                 "'纵轴表示数值的值',"
                                 "'这个文本块可以放在图中各',"
                                 "'种位置'].join('\\n')"),
                     font="14px Microsoft YaHei",
コード例 #22
0
     opts.GraphicGroup(
         graphic_item=opts.GraphicItem(
             rotation=JsCode("Math.PI / 4"),
             bounding="raw",
             right=110,
             bottom=110,
             z=100,
         ),
         children=[
             opts.GraphicRect(
                 graphic_item=opts.GraphicItem(left="center",
                                               top="center",
                                               z=100),
                 graphic_shape_opts=opts.GraphicShapeOpts(width=400,
                                                          height=50),
                 graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                     fill="rgba(0,0,0,0.3)"),
             ),
             opts.GraphicText(
                 graphic_item=opts.GraphicItem(left="center",
                                               top="center",
                                               z=100),
                 graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                     text="pyecharts bar chart",
                     font="bold 26px Microsoft YaHei",
                     graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                         fill="#fff"),
                 ),
             ),
         ],
     )
 ],
コード例 #23
0
ファイル: 天气.py プロジェクト: jy28smy/spider
bar = (Bar().add_xaxis(['个旧', '开远', '蒙自', '建水']).add_yaxis(
    '天数', [gj_good_day, ky_good_day, mz_good_day, js_good_day],
    bar_width=50).set_global_opts(
        title_opts=opts.TitleOpts(
            title='舒适温度天数',
            subtitle='17度 < 温度 < 24度',
            pos_top="6%",
            pos_left='5%',
        ),
        legend_opts=opts.LegendOpts(pos_left="20%", pos_top="8%"),
        graphic_opts=opts.GraphicText(
            graphic_item=opts.GraphicItem(left="center", top="2%", z=100),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                text='2011年1月至2021年4月个旧、开远、蒙自、建水气温分析',
                font="28px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#259FA1")))).set_series_opts(
                        label_opts=opts.LabelOpts(is_show=False),
                        markpoint_opts=opts.MarkPointOpts(data=[
                            opts.MarkPointItem(type_="max", name="最好"),
                            opts.MarkPointItem(type_="min", name="最差"),
                        ])))
bar.reversal_axis()

# 折线图,年平均气温
line = (Line().add_xaxis([
    '2011年', '2012年', '2013年', '2014年', '2015年', '2016年', '2017年', '2018年',
    '2019年', '2020年'
]).add_yaxis("个旧", gj_mean, is_smooth=True).add_yaxis(
    "开远", ky_mean,
    is_smooth=True).add_yaxis("蒙自", mz_mean, is_smooth=True).add_yaxis(
        "建水", js_mean, is_smooth=True).set_global_opts(
コード例 #24
0
def find_value_render(query_filter, x_label, x, result, Data, query,
                      table_path, answer):

    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff']
    # x = ['GDP', 'Industry', 'Architecture', 'Service']
    # y = [990865, 317109, 70904, 534233]
    # x1 = ["周一"]
    # y1 = [11]

    Y = []
    # for i in range(len(y)):
    #     if i==0:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": colorList[0],
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #         ))
    #     else:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": "blue",
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #             ))
    bar1 = Bar()
    bar1.add_xaxis(x)
    bar1.add_yaxis(result[0][0],
                   y_axis=result[0][1],
                   label_opts=opts.LabelOpts(position="insideTop"))
    bar1.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        title_opts=opts.TitleOpts(subtitle="When the search condition is " +
                                  query_filter,
                                  pos_left='center'),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "Q:" + ' ' + query + '\n' + "\n" + 'A:' + ' ' +
                        answer
                    ],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])
    bar2 = Bar()
    bar2.add_xaxis(x)
    for i in range(len(result)):
        bar2.add_yaxis(result[i][0], y_axis=result[i][1])
    bar2.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "\n" + "Q:" + ' ' + query + '\n' + "\n" + 'A:' +
                        ' ' + answer
                    ],
                    font="16px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])

    Label = []
    data = []
    for i in range(len(Data)):
        Label.append(str(Data[i][0]))
        data.append(Data[i][1])
    data = list(map(list, zip(*data)))
    parallel = Parallel()
    parallel_axis = []
    for i in range(len(Label)):
        parallel_axis.append({"dim": i, "name": Label[i]})
    parallel.add_schema(schema=parallel_axis)
    parallel.add("", data, is_smooth=True)
    parallel.set_global_opts(graphic_opts=[
        opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",
                z=100,
            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333")))
    ])
    grid0 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid0.add(bar1, grid_opts={'left': '20%', 'bottom': '34%'})
    option0 = grid0.dump_options_with_quotes()
    option0 = json.loads(option0)
    grid = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid.add(bar2, grid_opts={'left': '15%', 'bottom': '50%'})
    option1 = grid.dump_options_with_quotes()
    option1 = json.loads(option1)
    grid1 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid1.add(parallel, grid_opts={'left': '30%', 'bottom': '34%'})
    option2 = grid1.dump_options_with_quotes()
    option2 = json.loads(option2)

    option = {"option": [option1, option2], "query": query}
    return option
コード例 #25
0
 def line_render_qimai(self):
     c = Line(init_opts=opts.InitOpts(width="1200px", height="400px"))
     # c = Line()
     c.add_xaxis(self.x_value)
     c.add_yaxis(
         series_name=self.y_name,
         y_axis=self.y_value,
         is_symbol_show=self.is_symbol_show,  # 线上不用点标记
         color=self.color_list[0],
         linestyle_opts=opts.LineStyleOpts(width=self.line_width),  # 线条加粗
         label_opts=opts.LabelOpts(is_show=self.is_show))
     c.set_global_opts(
         title_opts=opts.TitleOpts(
             title=self.title,
             pos_top="2%",  # 距离顶层2%
             pos_left="center",
             title_textstyle_opts=opts.TextStyleOpts(
                 color="#666",
                 font_size=16,
                 font_weight='normal',
                 font_family='Microsoft YaHei'),
         ),
         tooltip_opts=opts.TooltipOpts(trigger="axis"),
         # legend_opts=opts.LegendOpts(pos_left="center", pos_top=self.pos_top, legend_icon='circle'),
         legend_opts=opts.LegendOpts(pos_left="center",
                                     pos_top='bottom',
                                     legend_icon='circle'),
         yaxis_opts=opts.AxisOpts(
             type_="value",
             max_=self.y_max,
             min_=self.y_min,
             is_inverse=self.y_is_inverse,  # 反向Y轴;
             boundary_gap=self.boundary_gap,  # 封闭坐标轴,左右都有顶上的刻度线;
             axislabel_opts=opts.LabelOpts(color="#7D7D7D"),
             axisline_opts=opts.AxisLineOpts(
                 linestyle_opts=opts.LineStyleOpts(width=1.5,
                                                   color="#A0A7B3")),
             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True),
             splitline_opts=opts.SplitLineOpts(
                 is_show=True,
                 linestyle_opts=opts.LineStyleOpts(
                     color="#E2E2E2")),  # 设置网格线;
         ),
         xaxis_opts=opts.AxisOpts(
             type_="category",
             min_=self.x_min,
             boundary_gap=self.boundary_gap,
             is_inverse=self.x_is_inverse,  # 反向X轴;
             axislabel_opts=opts.LabelOpts(color="#7D7D7D"),
             axisline_opts=opts.AxisLineOpts(
                 linestyle_opts=opts.LineStyleOpts(width=1.5,
                                                   color="#A0A7B3")),
             axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True),
             splitline_opts=opts.SplitLineOpts(
                 is_show=True,
                 linestyle_opts=opts.LineStyleOpts(color="#E2E2E2")),
         ),
         graphic_opts=[
             opts.GraphicGroup(
                 graphic_item=opts.GraphicItem(
                     rotation=JsCode("Math.PI / 500"),
                     bounding="raw",
                     right=700,
                     bottom=150,
                     z=100,
                 ),
                 children=[
                     opts.GraphicRect(
                         graphic_item=opts.GraphicItem(left="center",
                                                       top="center",
                                                       z=100),
                         graphic_shape_opts=opts.GraphicShapeOpts(
                             width=400, height=50),
                         graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                             fill="rgba(0,0,0,0)"),
                     ),
                     opts.GraphicText(
                         graphic_item=opts.GraphicItem(left="center",
                                                       top="center",
                                                       z=100),
                         graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                             text="七麦数据",
                             # font="bold 26px Microsoft YaHei",
                             font="26px Microsoft YaHei",
                             graphic_basicstyle_opts=opts.
                             GraphicBasicStyleOpts(fill="#D5D5D5"),
                         ),
                     ),
                 ],
             )
         ],
         # 下方为图片水印代码;
         #             graphic_opts=[
         #                 opts.GraphicImage(
         #                     graphic_item=opts.GraphicItem(
         #                         id_="logo",
         #                         left='142',
         #                         z='10',
         #                         # 距离上边界距离
         #                         top='340',
         #                         # 负数则显示在图表下层
         #                         z_level=-1
         #                     ),
         #                     graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
         #                         # 指定图片地址,最好选用png
         #                         image="https://tva1.sinaimg.cn/large/008eGmZEly1gmfcjqkwrkj302q00mq2q.jpg",
         #                         # 长设置
         #                         width=100,
         #                         height=23,
         #                         opacity=1,
         #                     ),
         #                 ),
         #             ]
     )
     # 插入其他y线条;
     if len(self.args) > 0:
         for num in range(len(self.args[0])):
             if num + 1 > len(self.color_list) - 1:
                 color_str = ''
             else:
                 color_str = self.color_list[num + 1]
             c.add_yaxis(
                 series_name=self.args[0][num],
                 y_axis=self.args[1][num],
                 is_symbol_show=self.is_symbol_show,  # 线上不用点标记
                 color=color_str,
                 linestyle_opts=opts.LineStyleOpts(
                     width=self.line_width),  # 线条加粗
                 label_opts=opts.LabelOpts(is_show=self.is_show),
             )
     self.c_render = c
     return c
コード例 #26
0
ファイル: Aggregation.py プロジェクト: jiangqicd/DT2VIS
def find_aggregation_render(x, y, flag, query, table_path, answer, y_name):
    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff']
    x_sum = ["Sum"]
    Sum = []
    Sum.append(sum(y))
    mean = np.mean(y)
    y1 = []
    y2 = []
    for i in range(len(y)):
        if y[i] >= mean:
            y1.append(round(mean, 2))
            y2.append(
                opts.BarItem(name=x[i],
                             value=round(y[i] - mean, 2),
                             label_opts=opts.LabelOpts(formatter="+{c}"),
                             itemstyle_opts=opts.ItemStyleOpts(color="red")))
        else:
            y1.append(round(y[i], 2))
            y2.append(
                opts.BarItem(name=x[i],
                             value=round(mean - y[i], 2),
                             label_opts=opts.LabelOpts(formatter="-{c}"),
                             itemstyle_opts=opts.ItemStyleOpts(color="green",
                                                               opacity=0.3)))
    if flag == "mean":
        bar = Bar()
        bar.add_xaxis(x)
        bar.add_yaxis(
            '',
            y_axis=y1,
            stack='stack1',
            label_opts=opts.LabelOpts(is_show=False),
            color="white",
            markline_opts=opts.MarkLineOpts(
                data=[opts.MarkLineItem(name="mean:", y=round(mean, 2))],
                label_opts=opts.LabelOpts(formatter="Mean:{c}", color="black"),
                linestyle_opts=opts.LineStyleOpts(color="gray")),
        )
        bar.add_yaxis('', y_axis=y2, stack='stack1')
        bar.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10, range_end=90),
                opts.DataZoomOpts(type_="inside")
            ],
            xaxis_opts=opts.AxisOpts(
                axislabel_opts=opts.LabelOpts(rotate=40, font_size='100%'),
                name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
            yaxis_opts=opts.AxisOpts(
                min_=int(min(y) - (max(y) - min(y)) / 10),
                name=y_name,
                axislabel_opts=opts.LabelOpts(font_size="100%"),
                name_textstyle_opts=opts.TextStyleOpts(font_size="100%")),
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + "\n" + 'A:' +
                            ' ' + answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        bar.render("aggregation.html")
        grid = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid.add(bar, grid_opts={'left': '15%', 'bottom': '34%'})
        grid1 = Grid()
        grid1.add(bar, grid_opts={'left': '15%', 'bottom': '34%'})
        grid1.render("mean.html")
        option1 = grid.dump_options_with_quotes()
        option1 = json.loads(option1)
        option = {"option": [option1], "query": query}
        return option
    elif flag == "sum":
        bar = Bar()
        bar.add_xaxis(x_sum)
        bar.add_yaxis('',
                      Sum,
                      label_opts=opts.LabelOpts(position="inside",
                                                formatter="Sum:{c}"),
                      color=colorList[0])
        for i in range(len(y)):
            Y = []
            Y.append(y[i])
            r = str(x[i])
            bar.add_yaxis('',
                          Y,
                          stack='stack1',
                          label_opts=opts.LabelOpts(position="inside",
                                                    formatter=r + ":{c}"),
                          tooltip_opts=opts.TooltipOpts(is_show=False))
        bar.set_global_opts(
            datazoom_opts=[
                opts.DataZoomOpts(range_start=10,
                                  range_end=90,
                                  orient="vertical"),
                opts.DataZoomOpts(type_="inside")
            ],
            graphic_opts=[
                opts.GraphicText(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="bottom",
                    ),
                    graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                        # 可以通过jsCode添加js代码,也可以直接用字符串
                        text=[
                            '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' +
                            answer
                        ],
                        font="14px Microsoft YaHei",
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            fill="#333")))
            ])
        grid = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG,
        ))
        grid.add(bar, grid_opts={'left': '15%', 'bottom': '34%'})
        option1 = grid.dump_options_with_quotes()
        option1 = json.loads(option1)
        option = {"option": [option1], "query": query}
        return option
コード例 #27
0
def bmap_custom() -> BMap:
    with open(
        os.path.join("fixtures", "bmap-custom-data.json"), "r", encoding="utf-8"
    ) as f:
        j = json.load(f)
    color_list = ["#070093", "#1c3fbf", "#1482e5", "#70b4eb", "#b4e0f3", "#ffffff"]
    c = (
        BMap()
        .add_schema(
            baidu_ak=BAIDU_MAP_AK,
            center=[116.46, 39.92],
            zoom=11.8,
            is_roam=True,
            map_style={
                "styleJson": [
                    {
                        "featureType": "water",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "land",
                        "elementType": "all",
                        "stylers": {"color": "#f3f3f3"},
                    },
                    {
                        "featureType": "railway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "all",
                        "stylers": {"color": "#999999"},
                    },
                    {
                        "featureType": "highway",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "geometry.fill",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "poi",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "green",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "subway",
                        "elementType": "all",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "manmade",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "local",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "arterial",
                        "elementType": "labels",
                        "stylers": {"visibility": "off"},
                    },
                    {
                        "featureType": "boundary",
                        "elementType": "all",
                        "stylers": {"color": "#fefefe"},
                    },
                    {
                        "featureType": "building",
                        "elementType": "all",
                        "stylers": {"color": "#d1d1d1"},
                    },
                    {
                        "featureType": "label",
                        "elementType": "labels.text.fill",
                        "stylers": {"color": "rgba(0,0,0,0)"},
                    },
                ]
            },
        )
        .add_js_funcs(
            """
        var lngExtent = [39.5, 40.6];
        var latExtent = [115.9, 116.8];
        var cellCount = [50, 50];
        var cellSizeCoord = [
            (lngExtent[1] - lngExtent[0]) / cellCount[0],
            (latExtent[1] - latExtent[0]) / cellCount[1]
        ];
        var gapSize = 0;

        function renderItem(params, api) {
            var lngIndex = api.value(0);
            var latIndex = api.value(1);
            var pointLeftTop = getCoord(params, api, lngIndex, latIndex);
            var pointRightBottom = getCoord(params, api, lngIndex + 1, latIndex + 1);

            return {
                type: 'rect',
                shape: {
                    x: pointLeftTop[0],
                    y: pointLeftTop[1],
                    width: pointRightBottom[0] - pointLeftTop[0],
                    height: pointRightBottom[1] - pointLeftTop[1]
                },
                style: api.style({
                    stroke: 'rgba(0,0,0,0.1)'
                }),
                styleEmphasis: api.styleEmphasis()
            };
        }

        function getCoord(params, api, lngIndex, latIndex) {
            var coords = params.context.coords || (params.context.coords = []);
            var key = lngIndex + '-' + latIndex;
            return coords[key] || (coords[key] = api.coord([
                +(latExtent[0] + lngIndex * cellSizeCoord[0]).toFixed(6),
                +(lngExtent[0] + latIndex * cellSizeCoord[1]).toFixed(6)
            ]));
        }
        """
        )
        .add(
            series_name="",
            data_pair=j["data"],
            type_=ChartType.CUSTOM,
            render_item=JsCode("renderItem"),
            itemstyle_opts=opts.ItemStyleOpts(color="yellow"),
            encode={"tooltip": 2},
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="BMap-Custom 图"),
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter=None),
            visualmap_opts=opts.VisualMapOpts(
                is_piecewise=True,
                pos_top="10",
                pos_left="10",
                is_inverse=True,
                pieces=[
                    {"value": i, "color": color_list[i]} for i in range(len(color_list))
                ],
                dimension=2,
                border_color="#ccc",
                border_width=2,
                background_color="#eee",
                range_opacity=0.7,
            ),
            graphic_opts=[
                opts.GraphicGroup(
                    graphic_item=opts.GraphicItem(
                        rotation=JsCode("Math.PI / 4"),
                        bounding="raw",
                        right=110,
                        bottom=110,
                        z=100,
                    ),
                    children=[
                        opts.GraphicRect(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_shape_opts=opts.GraphicShapeOpts(
                                width=400, height=50
                            ),
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="rgba(0,0,0,0.3)"
                            ),
                        ),
                        opts.GraphicText(
                            graphic_item=opts.GraphicItem(
                                left="center", top="center", z=100
                            ),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text="Made by pyecharts",
                                font="bold 26px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                    fill="#fff"
                                ),
                            ),
                        ),
                    ],
                )
            ],
        )
    )
    return c
コード例 #28
0
def find_difference_render(data,X,query,table_path,answer):
    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff',"#ca8622","#726930",]
    if len(data)==2:
        bar1=Bar()
        bar1.add_xaxis(X[1])
        bar1.add_yaxis("",data[0][1],label_opts=opts.LabelOpts(position="insideLeft"))
        bar1.reversal_axis()
        bar1.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10,range_end=90,orient="vertical"), opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                position="top"
            ),
            yaxis_opts=opts.AxisOpts(
                is_inverse=True
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        bar2=Bar()
        bar2.add_xaxis(X[1])
        bar2.add_yaxis("",data[1][1],label_opts=opts.LabelOpts(position="insideRight"))
        bar2.reversal_axis()
        bar2.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90, orient="vertical"),
                           opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                position="top",
                is_inverse=True
            ),
            yaxis_opts=opts.AxisOpts(
                is_inverse=True,
                position="right"
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid1 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ) )
        grid1.add(bar1, grid_opts=opts.GridOpts(
            pos_left="60%",pos_bottom="30%"
        ))
        grid1.add(bar2, grid_opts=opts.GridOpts(
            pos_right="60%",pos_bottom="30%"
        ))
        grid1.render("a.html")
        option1 = grid1.dump_options_with_quotes()
        option1 = json.loads(option1)
        lable=[]
        for i in range(len(X[1])):
            lable.append(opts.RadarIndicatorItem(name=X[1][i]))
        # r_data=[]
        # for record in data:
        #     r_data.append(record[1])
        radar=Radar(init_opts=opts.InitOpts(bg_color="#CCCCCC"))
        radar.add_schema(
            schema=lable,
            splitarea_opt=opts.SplitAreaOpts(
               is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
             ),
            textstyle_opts=opts.TextStyleOpts(color="#fff"),
        )
        for i in range(len(data)):
            radar.add(
                series_name=data[i][0],
                label_opts=opts.LabelOpts(is_show=False),
                data=[data[i][1]],
                linestyle_opts=opts.LineStyleOpts(
                    color=colorList[i],
                    width=3

                )
            )
        radar.set_global_opts(
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n'+"\n" + 'A:' + ' ' + answer],
                    font="10px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ))
        grid2.add(radar, grid_opts={'left': '20%', 'bottom': '40%',"top":"1%"})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        bar3=Bar()
        bar3.add_xaxis(X[1])
        for i in range(len(data)):
            bar3.add_yaxis(data[i][0],data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar3.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
            xaxis_opts=opts.AxisOpts(
                name=X[0]
            ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid3 = Grid(init_opts=opts.InitOpts(
            width="100%",
            height="100%",
            renderer=globals.RenderType.SVG, ))
        grid3.add(bar3, grid_opts={'left': '20%', 'bottom': '30%'})
        option3 = grid3.dump_options_with_quotes()
        option3 = json.loads(option3)
        option = {"option": [option1,option2,option3], "query": query}
        return option

    elif len(data)>2 and len(data[0][1])>1:
        lable=[]
        for i in range(len(X[1])):
            lable.append(opts.RadarIndicatorItem(name=X[1][i]))
        # r_data=[]
        # for record in data:
        #     r_data.append(record[1])
        radar=Radar(init_opts=opts.InitOpts(bg_color="#CCCCCC"))
        radar.add_schema(
            schema=lable,
            splitarea_opt=opts.SplitAreaOpts(
               is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
             ),
            textstyle_opts=opts.TextStyleOpts(color="#fff"),
        )
        radar.set_global_opts(
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        for i in range(len(data)):
            radar.add(
                series_name=data[i][0],
                label_opts=opts.LabelOpts(is_show=False),
                data=[data[i][1]],
                linestyle_opts=opts.LineStyleOpts(
                    color=colorList[i],
                    width=3

                )
            )

        grid1 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid1.add(radar, grid_opts={'left': '20%', 'bottom': '30%'})
        option1 = grid1.dump_options_with_quotes()
        option1 = json.loads(option1)
        bar = Bar()
        bar.add_xaxis(X[1])
        for i in range(len(data)):
          bar.add_yaxis(data[i][0], data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
          xaxis_opts=opts.AxisOpts(
            name=X[0]
          ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",

                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid2.add(bar, grid_opts={'left': '20%', 'bottom': '30%'})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        option = {"option": [option1,option2], "query": query}
        return option
    elif len(data)>2 and len(data[0][1])==1:
        bar = Bar()
        bar.add_xaxis(X[1])
        for i in range(len(data)):
          bar.add_yaxis(data[i][0], data[i][1],label_opts=opts.LabelOpts(is_show=False))
        bar.set_global_opts(
            datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90),
                           opts.DataZoomOpts(type_="inside")],
          xaxis_opts=opts.AxisOpts(
            name=X[0]
          ),
            graphic_opts=[opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333"
                    )
                )
            )]
        )
        grid2 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG, ))
        grid2.add(bar, grid_opts={'left': '20%', 'bottom': '34%'})
        option2 = grid2.dump_options_with_quotes()
        option2 = json.loads(option2)
        option = {"option": [option2], "query": query}
        return option