我刚开始将 D3 与 React 结合使用。我的 React 应用程序是由 create-react-app 创建的。
在我的 React 组件中,我使用 import * as d3 from 'd3'
我的代码如下:
this.xScale = d3.time.scale()
.domain(d3.extent(this.props.data, function (d) {
return d[_self.props.xData];
}))
.rangeRound([0, this.w]);
this.yScale = d3.scale.linear()
.domain([0,d3.max(this.props.data,function(d){
return d[_self.props.yData]+_self.props.yMaxBuffer;
})])
.range([this.h, 0]);
this.area = d3.svg.area()
.x(function (d) {
return this.xScale(d[_self.props.xData]);
})
.y0(this.h)
.y1(function (d) {
return this.yScale(d[_self.props.yData]);
}).interpolate(this.props.interpolations);
编译错误:
export 'time' (imported as 'd3') was not found in 'd3'
我在项目目录下使用 npm install d3 --save
导入 d3。
有人知道问题出在哪里吗?
最佳答案
您正在使用 D3 v4。下面的链接是将旧版本转换为您现在使用的版本的解决方案,应该很简单。
关于reactjs - 在 'time' 中找不到导出 'd3' (导入为 'd3' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377438/