无法在d3plus-react中从外部csv文件加载文件。

时间:2017-10-11 13:31:12

标签: reactjs d3plus

请找到以下代码:

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

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个,我想你在阅读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 }} />

    )
}
相关问题