无法通过本地服务器 运行 Vega-Lite 可视化示例

Unable to run Vega-Lite visualization example through local server

我正在学习 Vega-Lite。

当我尝试运行一个简单的条形图示例时。浏览器控制台抛出错误:

我是运行宁this example

我正在使用 webstorm IDE;它创建了一个本地服务器,我通过它向浏览器提供网页。我也用 python http 服务器进行了测试。结果是一样的。

错误:

Failed to load resource: the server responded with a status of 404 ()
vega-embed@4:1 The input spec uses Vega-Lite v4, but the current version of Vega-Lite is vnot available.  
(anonymous) @ vega-embed@4:1
vega-embed@4:1 Uncaught (in promise) TypeError: Cannot read property 'compile' of undefined
    at Object.vega-lite (vega-embed@4:1)
    at vega-embed@4:1
    at Generator.next (<anonymous>)
    at vega-embed@4:1
    at new Promise (<anonymous>)
    at ce (vega-embed@4:1)
    at Ke (vega-embed@4:1)
    at et (vega-embed@4:1)
    at barexample.html?_ijt=lq5v9im4hg0eforrhc1pcvqivf:55

解决方案:

更新脚本源解决了问题:

<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@4"></script>

编辑: 这是一个非常快速的变通方法,但不是一个合适的解决方案。 @tmori3y2 已经编写了正确的解决方案,并且文档也在 vega-lite 存储库上更新。

升级依赖项,不是 vega-embed@4 for vega-lite@4.0.0-beta.2

<script src="https://cdn.jsdelivr.net/npm/vega@5.6.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@4.0.0-beta.2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@5.1.2"></script>

<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@4.0.0-beta.2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@5"></script>