pyecharts运行后产生的html文件用浏览器打开空白怎么办

发布时间:2021-05-23 16:27:26 作者:小新
来源:亿速云 阅读:1243

小编给大家分享一下pyecharts运行后产生的html文件用浏览器打开空白怎么办,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

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

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

解决办法:

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

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

官方下载

pyecharts运行后产生的html文件用浏览器打开空白怎么办

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

# 只需要在顶部声明 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文件用浏览器打开空白怎么办”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. 如何加快网站的运行打开速度 html
  2. VScode中的html文件怎样用浏览器运行?

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pyecharts html 浏览器

上一篇:java GUI实现五子棋游戏的示例分析

下一篇:如何实现SpringSecurity rememberme功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》