【发布时间】:2018-03-04 18:49:02
【问题描述】:
我是使用 D3 和 React 的新手。我的反应应用程序是由 create-react-app 创建的。
在我的反应组件中,我使用 import * as d3 from 'd3' 导入 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);
得到编译错误:
在“d3”中找不到导出“时间”(导入为“d3”)
我在我的项目目录下使用npm install d3 --save 导入d3。
任何人有想法有什么问题?
【问题讨论】:
-
该代码使用的是 D3 v3。您正在导入 D3 v4。
-
@bennygenel 我遇到同样的错误如何解决?