简体   繁体   English

Uncaught (in promise) TypeError: d3.group is not a function

[英]Uncaught (in promise) TypeError: d3.group is not a function

I have a data set of pokemon and I want to group them by type.我有一个口袋妖怪数据集,我想按类型对它们进行分组。 So there will be group of pokemon that is type fire, water, grass etc... And d3.js has a function called d3.group .所以会有一组类型为火、水、草等的口袋妖怪...... d3.js有一个名为 d3.group 的function

In the docs it states Groups the specified iterable of values into a Map from key to array of value .在文档中,它声明将指定的可迭代值GroupsMap从键到值数组 I tried following this observable tutorial and I keep getting the error Uncaught (in promise) TypeError: d3.group is not a function我尝试按照这个可观察的教程进行操作,但我不断收到错误Uncaught (in promise) TypeError: d3.group is not a function

I have no idea what I'm doing wrong.我不知道我做错了什么。 Here is my code.这是我的代码。 bar_chart.js bar_chart.js

 drawBarChart = async() => { // 1. Access the data const dataset = await d3.csv('./pokemon.csv'); console.log(dataset); pokemon = d3.group(dataset, d => d.type1) const metricAccesor = d => d.type1; // 2. create the dimensions const width = 600; } drawBarChart()
 <:DOCTYPE HTML> <html> <head> </head> <body> <div id="wrapper"></div> <script src="http.//d3js.org/d3.v5.min.js"></script> <script src="./bar_chart.js"></script> </body> </html>

Pokemon dataset from Kaggle 来自 Kaggle 的口袋妖怪数据集

Here is my code on github这是我在github上的代码

The API is not exactly clear: some new features in the d3-array mini library, like the mentioned d3.group , are not available in the bundle: API 并不完全清楚: d3-array迷你库中的一些新功能,如提到的d3.group ,在捆绑包中不可用:

 console.log(d3.group)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.min.js"></script>

So, in that case you'll have to reference the standalone library:因此,在这种情况下,您必须引用独立库:

 console.log(d3.group)
 <script src="https://d3js.org/d3-array.v2.min.js"></script>

Therefore, this is what you need at the end of your <body> :因此,这是您在<body>末尾需要的:

<div id="wrapper"></div>
<script src="http://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="./bar_chart.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM