1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python画图保存成html格式 用浏览器打开页面为空白_解决pyecharts运行后产生的html文

python画图保存成html格式 用浏览器打开页面为空白_解决pyecharts运行后产生的html文

时间:2020-12-21 04:42:10

相关推荐

python画图保存成html格式 用浏览器打开页面为空白_解决pyecharts运行后产生的html文

根据网站资源引用说明:pyecharts 使用的所有静态资源文件存放于 pyecharts-assets 项目中,默认挂载在/assets/

因为默认优先从远程引用资源,这就导致有的时候无法加载js文件,图表显示不出来

解决办法:

下载所需js文件到本地,修改资源引用地址

看网站的介绍,pyecharts 提供了更改全局 HOST 的快捷方式

pyecharts-assets 提供了pyecharts的静态资源文件。

可通过 localhost-server 或者 notebook-server 启动本地服务。首先将项目下载到本地

# 通过 git clone

$ git clone /pyecharts/pyecharts-assets.git

# 或者直接下载压缩包

$ wget /pyecharts/pyecharts-assets/archive/master.zip

Localhost-Server

启动服务器

$ cd pyecharts-assets

$ python -m http.server

设置 host

# 只需要在顶部声明 CurrentConfig.ONLINE_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, OnlineHostType

# OnlineHostType.NOTEBOOK_HOST 默认值为 http://localhost:8888/nbextensions/assets/

CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST

# 接下来所有图形的静态资源文件都会来自刚启动的服务器

from pyecharts.charts import Bar

bar = Bar()

tips:

CurrentConfig.ONLINE_HOST = http://127.0.0.1:8000/assets/

可以直接修改为本机目录:

CurrentConfig.ONLINE_HOST = "E:/Software/pyecharts-assets-master/assets/"

到此这篇关于解决pyecharts运行后产生的html文件用浏览器打开空白的文章就介绍到这了,更多相关pyecharts 浏览器打开空白内容请搜索python博客以前的文章或继续浏览下面的相关文章希望大家以后多多支持python博客!

python画图保存成html格式 用浏览器打开页面为空白_解决pyecharts运行后产生的html文件用浏览器打开空白...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。