Javascript d3.js/React.js中的热图-图中不呈现rect元素

Javascript d3.js/React.js中的热图-图中不呈现rect元素,javascript,reactjs,d3.js,Javascript,Reactjs,D3.js,我正在尝试使用d3数据构建热图,但它不会渲染所有的方块: d3.csv("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/heatmap_data.csv", function(data) { setState(data) svg.selectAll() .data(state, function(d){ return d.group+ ':' +d.variab

我正在尝试使用d3
数据构建热图,但它不会渲染所有的方块:

d3.csv("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/heatmap_data.csv", function(data) {
   setState(data)
   svg.selectAll()
     .data(state, function(d){ return d.group+ ':' +d.variable ;})
     .enter()
     .append("rect")
     .attr("x", function(d) { return x(d.group) })
     .attr("y", function(d) { return y(d.variable) })
     .attr("width", x.bandwidth() )
     .attr("height", y.bandwidth() )
     .style("fill", 'red' )
  })
}, [])

在V6中,
d3.csv
作为承诺实现。另外,为
selectAll
指定正确的选择:

const [graphData, setGraphData] = useState(null);

...

d3.scv('https://...').then(data => setGraphData(data));

...

useEffect(() => {
  if (graphData) {
    svg.selectAll('rect')
      .data(graphData, d => `${d.group}:${d.variable}`)
      .enter()
      .append('rect')
      ...
  }
}, [graphData]);

你使用的是哪个版本的d3?嗨,迈克尔;)我使用的是最新版本,6.7.0,我尝试了很多方法,它是渲染的,但它没有像示例中那样定位自己,所以我暂时的解决方案是使用不同的数据库。好的,我明白了。非常感谢你!我要试试