示例#1
0
def bar_graphic_image_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 Image 组件示例"),
            graphic_opts=[
                opts.GraphicImage(
                    graphic_item=opts.GraphicItem(
                        id_="logo",
                        right=20,
                        top=20,
                        z=-10,
                        bounding="raw",
                        origin=[75, 75],
                    ),
                    graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
                        image="http://echarts.baidu.com/images/favicon.png",
                        width=150,
                        height=150,
                        opacity=0.4,
                    ),
                )
            ],
        )
    )
    return c
示例#2
0
def test_bar_graphic(fake_writer):
    c = (
        Bar()
        .add_xaxis(["A", "B", "C"])
        .add_yaxis("series0", [1, 2, 4])
        .set_global_opts(
            graphic_opts=[
                opts.GraphicImage(
                    graphic_item=opts.GraphicItem(
                        id_="logo",
                        right=20,
                        top=20,
                        z=-10,
                        bounding="raw",
                        origin=[75, 75],
                    ),
                    graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
                        image="http://echarts.baidu.com/images/favicon.png",
                        width=150,
                        height=150,
                        opacity=0.4,
                    ),
                )
            ]
        )
    )
    c.render()
    file_name, content = fake_writer.call_args[0]
    assert_equal("render.html", file_name)
    assert_in("graphic", content)
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))
示例#4
0
    def __init__(self,fields, title, subtitle='', y_name='', x_name=''):
        # 加入字段为了用来指定stack时的值
        self.fields=fields
        self.y_name = y_name
        self.x_name = x_name
        self.title = title
        self.subtitle = subtitle
        self.init_opts = opts.InitOpts(theme=ThemeType.LIGHT)
        self.logo = [
            opts.GraphicImage(
                graphic_item=opts.GraphicItem(
                    id_='logo',
                    right=20,
                    top=20,
                    z=-10,
                    bounding="raw",
                    origin=[75, 75]
                ),
                graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
                    image="logo.png",
                    width=110,
                    height=110,
                    opacity=0.4

                )
            )
        ]
示例#5
0
def bar_graphic_image_with_js_component() -> Grid:
    bar = (
        Bar(init_opts=opts.InitOpts(chart_id="1234"))
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values())
        .add_yaxis("商家B", Faker.values())
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Bar-Graphic Image(旋转功能)组件示例"),
            graphic_opts=[
                opts.GraphicImage(
                    graphic_item=opts.GraphicItem(
                        id_="logo",
                        right=20,
                        top=20,
                        z=-10,
                        bounding="raw",
                        origin=[75, 75],
                    ),
                    graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
                        image="http://echarts.baidu.com/images/favicon.png",
                        width=150,
                        height=150,
                        opacity=0.4,
                    ),
                )
            ],
        )
    )
    c = (
        Grid(init_opts=opts.InitOpts(chart_id="1234"))
        .add(
            chart=bar,
            grid_opts=opts.GridOpts(pos_left="5%", pos_right="4%", pos_bottom="5%"),
        )
        .add_js_funcs(
            """
            var rotation = 0;
            setInterval(function () {
                chart_1234.setOption({
                    graphic: {
                        id: 'logo',
                        rotation: (rotation += Math.PI / 360) % (Math.PI * 2)
                    }
                });
            }, 30);
        """
        )
    )
    return c
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid
from pyecharts.faker import Faker

bar = (Bar(init_opts=opts.InitOpts(chart_id="1234")).add_xaxis(Faker.choose(
)).add_yaxis("商家A", Faker.values()).add_yaxis(
    "商家B", Faker.values()).set_global_opts(
        title_opts=opts.TitleOpts(title="Bar-Graphic Image(旋转功能)组件示例"),
        graphic_opts=[
            opts.GraphicImage(
                graphic_item=opts.GraphicItem(id_="logo",
                                              right=20,
                                              top=20,
                                              z=-10,
                                              bounding="raw",
                                              origin=[75, 75]),
                graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
                    image="https://www.echartsjs.com/zh/images/favicon.png",
                    width=150,
                    height=150,
                    opacity=0.4,
                ),
            )
        ],
    ))
c = (Grid(init_opts=opts.InitOpts(chart_id="1234")).add(
    chart=bar,
    grid_opts=opts.GridOpts(pos_left="5%", pos_right="4%", pos_bottom="5%"),
).add_js_funcs("""
        var rotation = 0;
        setInterval(function () {
            chart_1234.setOption({