1 直接下载源码 放入 g2.min.js 文件
![](https://img.haomeiwen.com/i13918823/3ecbc76195fb9834.png)
2 js引入
<script src="/statics/admin/js/g2.min.js" language="JavaScript" ></script>
3 copy 示例到代码
报错
浏览器控制台
Uncaught (in promise) ReferenceError: Chart is not defined
at onlineCount.html:154
//提示引入错误
const chart = new Chart({
container: 'container',
autoFit: true,
height: 500,
padding: [30, 20, 70, 30]
});
修改后
const chart = new G2.Chart({
container: 'container',
autoFit: true,
height: 500,
padding: [30, 20, 70, 30]
});
//继续报错
g2.min.js:13117 Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
at new e (g2.min.js:13117)
at onlineCount.html:154
// container 对应id找不到
<!-- 创建图表容器 -->
<div id="c1"></div>
const chart = new G2.Chart({
container: 'c1',
autoFit: true,
height: 500,
padding: [30, 20, 70, 30]
});
显示成功
![](https://img.haomeiwen.com/i13918823/ac9b24466744594b.png)
网友评论