score:1
something like this will work :
d3.csv('linktocsvfilehere.csv',function(data){
var sumarray = [];
var janarray= [], febarray= [], marcharray = [];
data.foreach(function(d){
janarray.push(d.jan); //push all jan values into jan array
febarray.push(d.feb); //push all feb values into feb array
marcharray.push(d.march); //push all march values into march array
});
var jansum = getsumofarray(janarray); //get sum of jan array
var febsum = getsumofarray(febarray);
var marchsum = getsumofarray(marcharray);
sumarray.push(jansum,febsum,marchsum);
console.log(sumarray); //here is your array you want
function getsumofarray(array){
var thissum = 0;
for(var i = 0; i<array.length; i++){
thissum += array[i];
}
return thissum;
}
})
score:2
even though thatoneguy's answer is perfect, this is way shorter:
d3.csv("yourfile.csv", function(data){
var totalsum = [d3.sum(data.map(function(d){ return d.jan})),
d3.sum(data.map(function(d){ return d.feb})),
d3.sum(data.map(function(d){ return d.march}))];
console.log(totalsum);//[4, 9, 12]
});
Source: stackoverflow.com
Related Query
- How can we Sum the data of .csv file columnwise using d3.js
- In d3.js, while importing csv files using a row conversion, how can I "slice" the data to only include a range of rows?
- How to update data on a page according to data from a CSV file instead of using fixed element data on the page?
- How to update elements of an HTML that the elements are created using data from a CSV file?
- In a d3 scatterplot using data from a csv file, how do i draw lines connecting related points when the mouse is over a point?
- How to use nest in d3 to group using the 'month' as key, but my csv file contains the whole date?
- How can we load a CSV file into JupyterLab using d3?
- How can i use the data from Hbase to visualize using d3.js
- How can create a table with using filter on csv data
- How to load data from a CSV file in D3 v5
- Can d3.js draw two scatterplots on the same graph using data from the same source?
- Using d3.js, how can I display data faster on my chart?
- putting the country on drop down list using d3 via csv file
- Using Javascript D3 library, how can I determine mouse position in data set of an area element on mousemove event?
- How can I achieve the R kernel density estimate plot using D3.js?
- D3: How to dynamically refresh a graph by changing the data file source?
- How to plot animated line chart using d3 while the data table is required to be updated every 1 second?
- How can I sum binned time series using d3.js?
- How can i get the startAngle and endAngle of each arc in the sunburst example using d3.js?
- how can i group JSON data into the weeks according to calender?
- How do I read a CSV file into an array using d3js v5
- display data from csv file into BarGraph using d3.js
- How would I import a single column CSV file into a pie chart using Javascript D3?
- How can I add images in the nodes of a D3 Sankey diagram, using the rcv and networkD3 packages in R?
- Unable to reference d3.js data imported from a csv file with spaces in the header
- how to update data form file json using d3.js (zoomable circle pack)
- How can I offset the source and target points of a bezier curve using D3's link generator?
- d3: how can I load external CSV file into data?
- How to fetch data from json file to draw a dynamic graph by using d3.js
- How to iterate over data in JSON file using D3 javascript
More Query from same tag
- Populating d3.js tooltip from a array
- Transition all div elements with .tween at the same time with d3
- Why is my zoom wrong in this d3 code?
- Simple d3 bar graph doesn't show up
- Unable to update nodes position using d3 force and Svelte
- My developer visual stops working after declaring an object using d3-scale function
- D3 Axis ticks by Week of Year
- javascript d3 get the biggest value from a multi-nested array/object dataset
- Beginner: Importing CSV to D3
- How to relocate the labels on a zoomable map?
- geopath overlap after scale D3.js
- Problem with observables using httpclient
- How to draw clickable line in PIXI.js using PIXI.Graphics?
- yFiles Graphsource alternative(js or python) for "DAGs" or "networks"
- How to prevent the drag if the user clicks the round in d3.js?
- D3js Hive Plot : How to label nodes?
- Plot sparklines using D3.js with normalized data
- SVG 'tspan' element and content not matching
- Getting Slider Value - d3/dc
- Parsing CSV dates not working in D3.js
- Can I define data point color with a function when using angular-chart?
- marker-end not getting displayed
- D3.js chart call and re-plot area after zoomed
- Drawing shape within a charts that would override the current graph
- D3 mouse coordinates after transform
- How to highlight only one datapoint in c3.js line graph?
- D3js Force Link label's not showing
- Populating a select list of connected nodes in d3.js
- Problems while reproducing Sankey chart example with d3_sankey
- d3.tree get min & max value