So, i'm trying to import data to draw a line chart. The following :
import input from './data.json';
d3.json(input, function(err, d){
console.log(d)
});
Doesn't work, and returns:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
That's data.json :
[
{"date" : "12/09/17", "value": 83, "module": 0},
{"date" : "19/09/17", "value": 79, "module": 1},
{"date" : "26/09/17", "value": 78, "module": 2},
{"date" : "30/09/17", "value": 73, "module": 3},
{"date" : "08/10/17", "value": 71, "module": 4},
{"date" : "15/10/17", "value": 67, "module": 5},
{"date" : "22/10/17", "value": 65, "module":6}
]
If I attempt to import the data in csv format, it does not work either. With a console log in the d3.csv function, it will log 0, 1, 2, 3, 4 .... basically the index of each data.
What am I missing here ? Is it something wrong with the way data is imported ? I'm struggling to identify what is wrong. I've browsed several examples on blockbuilder. There aren't many ways to import data.
EDIT : my react component :
class Reactchart extends React.Component {
componentDidMount(){
this.myfunc();
}
componentDidUpdate(){
this.myfunc();
}
myfunc() {
d3.json(input, function(err, d){
console.log(d) });
}
}
}