【问题标题】:Not able to load file from external csv file in d3plus-react.无法从 d3plus-react 中的外部 csv 文件加载文件。
【发布时间】:2017-10-11 21:44:12
【问题描述】:

请找到以下代码:

class Timedown extends Component {
  state = {
    data: d3.csv("./data/d3plus.csv", function(error, dataset) {
      if (error) return console.error(error);
    })
};

【问题讨论】:

    标签: reactjs d3plus


    【解决方案1】:

    试试这个,我想你在读取 csv 文件后不会返回数据。

        d3.csv('./data/d3plus.csv', (err, data) => {
            if (err) {
                console.log(err)
                return;
            }
            ReactDOM.render(
                <App width={960} height={640} data={data} />,
                document.getElementById('root'),
            )
        });
    
    function App({width, height, data}) {
        const config = { data, x: "year", y: "value", text: "name" }; 
        return (
           // you can manipulate the data here using data
          // your html goes here
           <LinePlot config={{ config }} />
    
        )
    }
    

    【讨论】:

    • 我有 index.js,我在其中渲染了根 dom 元素,当我提到数据时,代码正在工作,正如您从代码中的图像中看到的那样
    • 那么问题是数据似乎没有与 LinePlot 绑定。直接尝试使用这个
    • 看看这个渲染方法,render() { const { data } = this.state; const config = { data, x: "year", y: "value", text: "name" };返回 ; } }
    • 不要使用双大括号 {{ }} 使用单大括号
    • 我尝试使用 {} 但仍然无法正常工作。 Config 是一个对象,因此我认为应该在 {{}} 中提及
    猜你喜欢
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多