老师的代码这里不起作用
来源:4-2 antv-g2 入门

acai_0002
2020-10-03
渲染出来没有宽高,要给div增加一个宽和高才能显示出来,是不是G2更新了?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/@antv/g2plot@latest/dist/g2plot.min.js"></script>
<style>
#g2-chart{
width: 400px;
height: 300px;
}
</style>
<title>G2</title>
</head>
<body>
<div id="g2-chart"></div>
<script>
const data = [
{ year: '1991', value: 3 },
{ year: '1992', value: 4 },
{ year: '1993', value: 3.5 },
{ year: '1994', value: 5 },
{ year: '1995', value: 4.9 },
{ year: '1996', value: 6 },
{ year: '1997', value: 7 },
{ year: '1998', value: 9 },
{ year: '1999', value: 13 },
];
const chartDom = document.getElementById('g2-chart');
const line = new G2Plot.Line(chartDom, {
title: {
visible: true,
text: 'G2折线图示例'
},
data,
xField:'year',
yField:'value'
});
line.render();
</script>
</body>
</html>
1回答
-
扬_灵
2020-10-03
同学你好,是这样的,最新版本中的G2是需要设置元素的宽高的。
10
相似问题