pyecharts的animation的关闭

在利用pyecharts库绘制并保存图片时,
当生成html页面后,再利用snapshot截屏时,截屏有延迟时间设置,
若时间设置过多,结果就是当初始动画还没加载完就完成截屏,
为了保证在绘制多张图片时,时间不至于延迟过长,我打算在add()中配置类似animation:false的设置,
但找不到相对应属性,求助是否有该属性?
屏幕快照 2017-09-11 20.22.45
clipboard.png

阅读 5.3k
3 个回答

现在再看这个问题,当时并没有找到封装好的接口,现在的思路是生成html页面后再对html页面进行修改,自问自答,有不同建议欢迎骚扰

查询到画图动画初始化配置(animation_opts)在InitOpts中配置,以dict字典的形式:

class InitOpts(BasicOpts):
    def __init__(
        self,
        width: str = "900px",
        height: str = "500px",
        chart_id: Optional[str] = None,
        renderer: str = RenderType.CANVAS,
        page_title: str = CurrentConfig.PAGE_TITLE,
        theme: str = ThemeType.WHITE,
        bg_color: Union[str, dict] = None,
        js_host: str = "",
        animation_opts: Union[AnimationOpts, dict] = AnimationOpts(),
    )

如果你想绘制一张饼图,并且做一些全局配置,你需要先从pyecharts.charts中导入Pie再从pyecharts中导入options模块:
from pyecharts.charts import Pie
from pyecharts import options as opts
然后创建饼图Pie对象,将创建的Pie对象赋值给pie
注意初始化的配置不能通过set_global_opts方法配置,可以查看set_global_opts方法中能配置哪些:

def set_global_opts(
        self,
        title_opts: types.Title = opts.TitleOpts(),
        legend_opts: types.Legend = opts.LegendOpts(),
        tooltip_opts: types.Tooltip = None,
        toolbox_opts: types.Toolbox = None,
        brush_opts: types.Brush = None,
        xaxis_opts: types.Axis = None,
        yaxis_opts: types.Axis = None,
        visualmap_opts: types.VisualMap = None,
        datazoom_opts: types.DataZoom = None,
        graphic_opts: types.Graphic = None,
        axispointer_opts: types.AxisPointer = None,
    )

但是初始化的配置能在创建Pie对象时配置

class Pie(
    # 初始化配置项,参考 `global_options.InitOpts`
    init_opts: opts.InitOpts = opts.InitOpts()
)

animation默认是True,开启画图动画:

class AnimationOpts(BasicOpts):
    def __init__(
        self,
        animation: bool = True,
        animation_threshold: Numeric = 2000,
        animation_duration: Union[Numeric, JSFunc] = 1000,
        animation_easing: Union[str] = "cubicOut",
        animation_delay: Union[Numeric, JSFunc] = 0,
        animation_duration_update: Union[Numeric, JSFunc] = 300,
        animation_easing_update: Union[Numeric] = "cubicOut",
        animation_delay_update: Union[Numeric, JSFunc] = 0,
    )

所以如果想关闭绘图动画,你需要在创建饼图对象时进行初始化设置:

pie = Pie(init_opts=opts.InitOpts(animation_opts={'animation': False}))
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题