Not able to load file from external csv file in d3plus-react. Please find the following code

70 views
Skip to first unread message

sandeep patil

unread,
Oct 10, 2017, 5:15:50 PM10/10/17
to d3plus
class Timedown extends Component {
  state = {
    data: d3.csv("./data/d3plus.csv", function(error, dataset) {
      if (error) return console.error(error);
    })
};
Message has been deleted

sandeep patil

unread,
Oct 13, 2017, 11:51:44 AM10/13/17
to d3plus
Please hepl me!

import React, { Component } from "react";
import { LinePlot } from "d3plus-react";
import { csv } from "d3-request";

class Timedown extends Component {
  state = {};
  componentDidMount() {
    csv("./data/d3plus.csv", (error, data) => {
      if (error) {
        this.setState({ loadError: true });
      }
      this.setState({
        data: data.map(d => ({
          ...d,
          x: Number(d.sec),
          y: Number(d.Value),
          a: String(d.Name)
        }))
      });
      console.log(data);
    });
  }
  render() {
    if (this.state.loadError) {
      return <div>couldn't load file</div>;
    }
    if (!this.state.data) {
      return <div />;
    }
    const { data } = this.state;
    console.log(data);
    const config = {
      data,
      x: "sec",
      y: "Value",
      text: "Name"
    };
    return data ? <LinePlot config={{ config }} /> : <p>No Data!</p>;
  }
}

export default Timedown;

Reply all
Reply to author
Forward
0 new messages