Javascript d3js enter不是一个函数问题

Javascript d3js enter不是一个函数问题,javascript,html,d3.js,Javascript,Html,D3.js,我是d3js图书馆的新手。我尝试绘制非洲大陆轮廓,我有以下代码: <!DOCTYPE html> <meta charset="utf-8"> <head> <title>geoPath measures</title> </head> <body> <svg id="my_dataviz" width="400" height="

我是d3js图书馆的新手。我尝试绘制非洲大陆轮廓,我有以下代码:

<!DOCTYPE html>
<meta charset="utf-8">
<head>
  <title>geoPath measures</title>
</head>

<body>
<svg id="my_dataviz" width="400" height="300"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js"></script>

<script>
  var svg = d3.select('#my_dataviz');
  var projection = d3.geoMercator().center([0, 5]);
  var geoGenerator = d3.geoPath().projection(projection);

  function update(geojson) {
    svg.append("g")
      .selectAll("path")
      .data(geojson.features)
      .enter()
        .append("path")
        .attr('d', geoGenerator);
  }

  d3.json('africa.json', function(err, json) {
    update(json)
  })
</script>
</body>
</html>
问题是什么?我做错了什么?

您的是
topoJson
,但您将其视为
geoJson
。正如@AndrewReid指出的,它没有
.features
属性

您可以使用将其转换为:


地质路径措施
var svg=d3.select('my#u dataviz');
var projection=d3.geoMercator().center([0,5]);
var geoGenerator=d3.geoPath().projection(projection);
函数更新(someTopoJson){
让geojson=topojson.feature(
某某,
someTopoJson.objects.Continume\u Africa\u子单元
);
svg
.append('g')
.selectAll('路径')
.data(geojson.features)
.输入()
.append('路径')
.attr('d',地球发电机)
.attr('fill','steelblue');
}
d3.json(
'https://raw.githubusercontent.com/deldersveld/topojson/master/continents/africa.json',
函数(err,json){
更新(json);
}
);

最可能的错误原因可能是geojson.features不是数组。你能记录下来确认一下吗?是的,安德鲁,这是个问题。谢谢谢谢马克,这解决了我的问题。
Uncaught TypeError: svg.append(...).selectAll(...).data(...).enter is not a function