Andy897
Andy897

Reputation: 7133

sum of columns in csv using d3

I have a csv file which has timestamp, value1, value2, value3

I am trying to create a pie chart in which three slices correspond to sum of value1, value2 and value3 column respectively. So, slice1 corresponds to sum of all values in first column , slice2 will correspond to sum of all values in second column and so on.

I know that we can group based on a column value, but not sure how to achieve this.

Please suggest

Upvotes: 1

Views: 2008

Answers (1)

Nikos
Nikos

Reputation: 3297

I think this should get you started:

d3.csv(<yourfile.csv>, function(data) {
    D={
        slice1:d3.sum(data, function(d){return parseFloat(d.value1);}),
        slice2:d3.sum(data, function(d){return parseFloat(d.value2);}),
        slice3:d3.sum(data, function(d){return parseFloat(d.value3);})
    }
})

Upvotes: 4

Related Questions