I started learning D3js and there is one thing that I would like to understand.
Why can I transform data easly when reading in CSV, but not when I use json.
There it goes an example: I read csv from an API and then I parse to numeric one of the key:value of the object (that comes as string):
const urlData = "https://analisi.transparenciacatalunya.cat/resource/7xn6-46kz.csv?$where=any = 2018&$select=nom_sector,SUM(co2eq)&$group=nom_sector&$order=SUM(co2eq) DESC";
const [data, setData] = React.useState(null);
React.useEffect(() => {
const row = (d) => {
d.emision = +d['SUM_co2eq'];
return d;
}
d3
.csv(urlData, row)
.then(setData)
}, []);
The data can be read as JSON with the same structure, just changing 7xn6-46kz.csv to 7xn6-46kz.json and the reading method to json(). The structure is the same but the parsing-to-numeric logic doesn't work. Why is that? Any ideas??