I have the following local csv file:
country,population,porcentage
China,15,1.1
India,86,4.1
United States,357,15.2
Indonesia,1207,51.2
Brazil,717,29.12
What I'm trying to do is to get the total value of population column in order to show it below my bar chart. I'm using d3 csv function to work with the data but the problem is that when I get the data the function is putting it in separate objects which is not allow me to add them up. This is how they look.
I have tried first with reduce but it doesn't work.
import { csv, sum } from 'd3';
csv("./src/bardata.csv", (() => {
var sum;
return sum = (...args) => {
return args.reduce((a, b) => a + b, 0);
};
}))();
I have also tried using map function but my understanding is that this only works with arrays and my data is in separate objects. Anyway, I keep recieving "data.map is not a function " error. Any suggestions?