gpt4 book ai didi

javascript - Chartist.js 抛出 TypeError : a is null

转载 作者:行者123 更新时间:2023-11-30 15:56:31 25 4
gpt4 key购买 nike

我知道我在这里遗漏了一些愚蠢的东西。知道为什么我无法呈现我的图表吗?

TypeError: a is null 控制台中的错误消息。

<html>
<head>
<title>My first Chartist Tests</title>
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">

</head>
<body><script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>


<script type="text/javascript">

new Chartist.Line('.ct-chart', {
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
series: [
[12, 9, 7, 8, 5],
[2, 1, 3.5, 7, 3],
[1, 3, 4, 5, 6]
]
}, {
fullWidth: true,
chartPadding: {
right: 40
}
});

</script>
<div class="ct-chart ct-perfect-fourth"></div>
</body>
</html>

最佳答案

live example

您应该在 dom 完全加载后执行 js 代码。尝试将您的脚本移动到 div(正文末尾)之后。

<html>
<head>
<title>My first Chartist Tests</title>
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">

</head>
<body>
<div class="ct-chart ct-perfect-fourth"></div>

<script type="text/javascript" src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>

<script type="text/javascript">

new Chartist.Line('.ct-chart', {
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
series: [
[12, 9, 7, 8, 5],
[2, 1, 3.5, 7, 3],
[1, 3, 4, 5, 6]
]
}, {
fullWidth: true,
chartPadding: {
right: 40
}
});

</script>
</body>
</html>

关于javascript - Chartist.js 抛出 TypeError : a is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com