reactjs - 在 'time' 中找不到导出 'd3' (导入为 'd3' )

标签 reactjs d3.js

我刚开始将 D3 与 React 结合使用。我的 React 应用程序是由 create-react-app 创建的。 在我的 React 组件中,我使用 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);

编译错误:

export 'time' (imported as 'd3') was not found in 'd3'

我在项目目录下使用 npm install d3 --save 导入 d3。

有人知道问题出在哪里吗?

最佳答案

您正在使用 D3 v4。下面的链接是将旧版本转换为您现在使用的版本的解决方案,应该很简单。

https://github.com/d3/d3/blob/master/CHANGES.md

关于reactjs - 在 'time' 中找不到导出 'd3' (导入为 'd3' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377438/

相关文章:

java - play 框架返回 415(不支持的媒体类型)

ajax - Apollo GraphQL 响应在 chrome devtools 中是不可见的

json - 使用新数据启动 D3.js 数据映射

javascript - 从嵌套数据绘制多折线图

javascript - D3.js 中的可折叠树

javascript - 有什么方法可以使用 testcafe 上传文件夹吗?

javascript - 冲突事件 : onKeyPress & onClick

javascript - React.js 中的非原始默认 props?

javascript - d3 - 标记日历示例

javascript - D3js,如何根据轴值(而不是像素)设置点