我是新手,使用D3和React.我的反应应用程序是由create-react-app创建的.在我的react组件中,我使用导入d3import * 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);
Run Code Online (Sandbox Code Playgroud)
得到了编译错误:
'd3'中未找到导出'时间'(导入为'd3')
我npm install d3 --save
在我的项目目录下导入d3 .
任何人都有想法是什么问题?
使用 d3.timeScale() 而不是 d3.time.scale()
D3.js 语法在版本 4 中发生了变化,因此不再使用 d3.time。
您要么需要导入 d3.js 版本 3
npm install d3@3
或更改您的代码以使用 d3.js 版本 4 语法
d3.timeScale();
归档时间: |
|
查看次数: |
11025 次 |
最近记录: |