这个问题其实是因为在内网机器上,pyecharts的渲染资源访问不到,可以参考这个
https://github.com/pyecharts/pyecharts-assets
这里有一个非常重要的提醒,如果说你按照官网教程给静态资源的方法,确定在输入没有问题的情况下,进行了尝试还是不行,我的建议是,先重新启动jupyter,如果还不行就重启一下电脑就完了
pyecharts-assets
pyecharts-assets 提供了 pyecharts 的静态资源文件。
可通过 localhost-server 或者 notebook-server 启动本地服务。首先将项目下载到本地
通过 git clone$ git clone https://github.com/pyecharts/pyecharts-assets.git
或者直接下载压缩包$ wget https://github.com/pyecharts/pyecharts-assets/archive/master.zip
Localhost-Server
启动服务器
$ cd pyecharts-assets
$ python -m http.server
设置 host
from pyecharts.globals import CurrentConfig CurrentConfig.ONLINE_HOST = "http://127.0.0.1:8000/assets/"接下来所有图形的静态资源文件都会来自刚启动的服务器
from pyecharts.charts import Bar bar = Bar() Notebook-Server
安装扩展插件
$ cd pyecharts-assets安装并激活插件
$ jupyter nbextension install assets $ jupyter nbextension enable assets/main
设置 host
只需要在顶部声明 CurrentConfig.ONLINE_HOST 即可from pyecharts.globals import CurrentConfig, onlineHostTypeOnlineHostType.NOTEBOOK_HOST 默认值为 http://localhost:8888/nbextensions/assets/
CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST接下来所有图形的静态资源文件都会来自刚启动的服务器
from pyecharts.charts import Bar bar = Bar()
这是一个官网上的方法,笔者还尝试了另外两种方法可以作为参考,当然仍然还是需要上述的静态资源文件,但是可以使用绝对路径进行引入,举个例子,假如我的pyecharts的静态资源路径是:
/home/xxx/pyecharts-assets/
那我就可以:
from pyecharts.globals import CurrentConfig CurrentConfig.ONLINE_HOST = "/home/xxx/pyecharts-assets/assets/"
这样生成的html文件或者说我在jupyter里render的对象
然后可以直接使用html魔法命令把js文件导入进去
这样的话还可以使用更多的html的标签工具来增强jupyter的性能:
如何在jupyter notebook中运行javascript和HTML代码



