解决pyecharts运行后产生的html文件用浏览器打开空白
根据网站资源引用说明:pyecharts使用的所有静态资源文件存放于pyecharts-assets项目中,默认挂载在 https://assets.pyecharts.org/assets/
因为默认优先从远程引用资源,这就导致有的时候无法加载js文件,图表显示不出来
解决办法:
下载所需js文件到本地,修改资源引用地址
看网站的介绍,pyecharts提供了更改全局HOST的快捷方式
官方下载
pyecharts-assets提供了 pyecharts 的静态资源文件。
可通过localhost-server或者notebook-server启动本地服务。首先将项目下载到本地
#通过gitclone $gitclonehttps://github.com/pyecharts/pyecharts-assets.git #或者直接下载压缩包 $wgethttps://github.com/pyecharts/pyecharts-assets/archive/master.zip
Localhost-Server
启动服务器
$cdpyecharts-assets $python-mhttp.server
设置host
#只需要在顶部声明CurrentConfig.ONLINE_HOST即可 frompyecharts.globalsimportCurrentConfig CurrentConfig.ONLINE_HOST="http://127.0.0.1:8000/assets/" #接下来所有图形的静态资源文件都会来自刚启动的服务器 frompyecharts.chartsimportBar bar=Bar()
Notebook-Server
安装扩展插件
$cdpyecharts-assets #安装并激活插件 $jupyternbextensioninstallassets $jupyternbextensionenableassets/main
设置host
#只需要在顶部声明CurrentConfig.ONLINE_HOST即可 frompyecharts.globalsimportCurrentConfig,OnlineHostType #OnlineHostType.NOTEBOOK_HOST默认值为http://localhost:8888/nbextensions/assets/ CurrentConfig.ONLINE_HOST=OnlineHostType.NOTEBOOK_HOST #接下来所有图形的静态资源文件都会来自刚启动的服务器 frompyecharts.chartsimportBar 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浏览器打开空白内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。