Ejemplo n.º 1
0
def charts():
    fp = open('./oldData.txt', 'r')

    # Timeline
    timeline = Timeline(init_opts=opts.InitOpts(
        width="1660px",
        height="708px",
    ))

    # 48 bar charts
    for i in range(48):
        X, Y, Color = getSta(fp)

        # y-axle with color
        y = []
        for j in range(22):
            y.append(
                opts.BarItem(
                    name=X[j],
                    value=Y[j],
                    itemstyle_opts=opts.ItemStyleOpts(color=Color[j])))

        # single bar chart
        bar = (
            Bar().add_xaxis(X).add_yaxis(
                "Youbike 使用率", y).reversal_axis().set_global_opts(
                    title_opts=opts.TitleOpts(
                        title="南港區Youbike的一天",
                        pos_left="center",
                    ),
                    legend_opts=opts.LegendOpts(pos_left="left"),
                    graphic_opts=[
                        opts.GraphicGroup(  # add a block
                            graphic_item=opts.GraphicItem(left="80%",
                                                          top="80%"),
                            children=[
                                opts.GraphicText(  # add text into the block
                                    graphic_item=opts.GraphicItem(
                                        left="center",
                                        top="center",
                                        # z=100
                                    ),
                                    graphic_textstyle_opts=opts.
                                    GraphicTextStyleOpts(
                                        text="{}".format(invTime[i]),
                                        font="48px Verdana",
                                    ),
                                )
                            ])
                    ]).set_series_opts(  # number showed at right of the bar
                        label_opts=opts.LabelOpts(position="right",
                                                  color="#333")))
        timeline.add(bar, "")  # add single bar chart into timeline
        timeline.add_schema(play_interval=1000,
                            is_loop_play=True)  # play settings

    # export into HTML
    timeline.render("YoubikeUsingRate.html")

    fp.close()
def draw_bar(df, date_list, tl):
    for date in date_list:
        _date = date[-5:]
        df4 = get_data(df, date)
        x = df4['country'].to_list()
        y = df4['confirmed'].to_list()

        bar = (Bar(init_opts=opts.InitOpts(
            theme=ThemeType.ROMANTIC)).add_xaxis(x).add_yaxis(
                "确诊人数", y).reversal_axis().set_series_opts(
                    label_opts=opts.LabelOpts(is_show=True,
                                              position='right'), ).
               set_global_opts(
                   legend_opts=opts.LegendOpts(is_show=True),
                   title_opts=opts.TitleOpts("{} Day".format(_date)),
                   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(_date),
                                       font="bold 26px Microsoft YaHei",
                                       graphic_basicstyle_opts=opts.
                                       GraphicBasicStyleOpts(fill="#fff"),
                                   ),
                               ),
                               opts.GraphicImage(
                                   graphic_item=opts.GraphicItem(left="center",
                                                                 top="center",
                                                                 z=100),
                                   graphic_imagestyle_opts=opts.
                                   GraphicImageStyleOpts(
                                       graphic_basicstyle_opts=opts.
                                       GraphicBasicStyleOpts(fill='#fff'))),
                           ],
                       )
                   ],
               ))
        tl.add(bar, "{}".format(_date))
Ejemplo n.º 3
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
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  
Ejemplo n.º 5
0
 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]),
     )
Ejemplo n.º 6
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
Ejemplo n.º 7
0
# 柱状图,适宜天数
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(
Ejemplo n.º 8
0
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
                        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))
tl.render("timeline_bar_with_graphic.html")
Ejemplo n.º 10
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
Ejemplo n.º 11
0
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
Ejemplo n.º 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
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
                        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"),
                        ),
                    ),
                ],
            )
        ],
    ).render("graphic_rect_bar1.html"))
Ejemplo n.º 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
Ejemplo n.º 17
0
            #         shadow_offset_y=3,
            #         shadow_color='rgba(0,0,0,0.3)',  # 阴影颜色
            #     )
            # ),
            # 配置文本
            opts.GraphicText(
                # 配置文本的位置
                graphic_item=opts.GraphicItem(
                    left='center',
                    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
)
Ejemplo n.º 18
0
                        #原生图形基础配置项
                        graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                            # 填充色
                            fill="rgba(0,0,0,0.3)"),
                    ),
                    #原生图形文本配置项
                    opts.GraphicText(
                        #GraphicItem:原生图形配置项
                        #left:描述怎么根据父元素进行定位。   top :配置和 left 及 right 相同    z 方向的高度,决定层叠关系。
                        graphic_item=opts.GraphicItem(left="center",
                                                      top="center",
                                                      z=100),
                        #图形文本样式的配置项
                        #原生图形文本样式配置项
                        graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                            #text:文本块文字。可以使用 \n 来换行
                            text="pyecharts bar chart",
                            # font:字体大小、字体类型、粗细、字体样式。
                            font="bold 26px Microsoft YaHei",
                            # 图形基本配置项
                            # 原生图形基础配置项
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                # 填充色
                                fill="#fff"),
                        ),
                    ),
                ],
            )
        ],
    ).render("bar_graphic_component.html"))
 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")
   )
Ejemplo n.º 20
0
        children=[
            # # 设置文本框
            # opts.GraphicRect(
            #
            # ),
            # 设置文本
            opts.GraphicText(
                # 配置的文本相对于 --->文本框的位置
                graphic_item=opts.GraphicItem(
                    left='center',  # 文本相对于文本框的左位置
                    top='middle',  # 文本相对文本框的上位置
                    z=100,  # 字在文本框的z轴方向100的位置
                    scale=[2.5, 2.5],  # [横向缩放的倍数, 纵向缩放的倍数]
                ),
                # 设置文本内容
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 文本内容
                    text="""截止2020-01-22日\n武汉封城前的迁徙路线""",
                    font='13px Microsoft YaHei',  # 字体
                    text_align='left',  # 水平对其方式: 左对齐
                    text_vertical_align='middle',  # 垂直对其方式:居中
                    # 图形化基本设置
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill='#ffdf22'  # 设置颜色
                    )))
        ]))

# 4、系列配置
geo.set_series_opts(
    # 标签设置
    label_opts=opts.LabelOpts(is_show=False))
Ejemplo n.º 21
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
        offset: 1,
        color: 'rgba(0, 77, 167, 1)'
    }
], false)
"""
            ),
            "barBorderRadius": [30, 30, 30, 30],
            "shadowColor": "rgb(0, 160, 221)"
        }
    }
}
GRAPH = {
    "text": lambda x: opts.GraphicText(
        graphic_item = opts.GraphicItem(
            left="center",
            top="center",
            z=100
        ),
        graphic_textstyle_opts = (
            text=x,
            font="bold 26px Microsoft Yahei",
            graphic_basicstyle_opts=opts.GraphicBacisStyleOpts(
                fill="#ffffff"
            )
        )
    ),
    "rect": opts.GraphicRect(
        graphic_item = opts.GraphicItem(
            left="center",
            top="center",
            z=100
        ),
Ejemplo n.º 24
0
                            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                                fill="rgba(0,0,0,0.3)",
                                #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=500),
                            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                                text="\n\n".join(top_titles[idx][:5]),
                                font="10px Microsoft YaHei",
                                graphic_basicstyle_opts=opts.
                                GraphicBasicStyleOpts(fill="#fff"),
                            ),
                        ),
                    ],
                )
            ],
        )
        wc_tl.add(wc, date)
        idx += 1

    bar = Bar(init_opts=opts.InitOpts(width="1200px", height="600px"))
    bar.add_xaxis(dates)
    for i in range(3):
Ejemplo n.º 25
0
            #
            # ),
            # 设置文本
            opts.GraphicText(
                # 配置的文本相对于 --->文本框的位置
                graphic_item=opts.GraphicItem(
                    left='center',  # 文本相对于文本框的左位置
                    top='middle',  # 文本相对文本框的上位置
                    z=100,  # 字在文本框的z轴方向100的位置
                    scale=[1.3, 1.5],  # [横向缩放的倍数, 纵向缩放的倍数]
                ),
                # 设置文本内容
                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增加系列配置
Ejemplo n.º 26
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