Public
Edited
Oct 24, 2023
1 fork
4 stars
Insert cell
Insert cell
d3.sum([1, 2, 3, -0.5])
Insert cell
Insert cell
plastics // See the Appendix below.
Insert cell
d3.sum(plastics, d => d.weight)
Insert cell
Insert cell
d3.sum(plastics, d => d.value)
Insert cell
Insert cell
d3.sum(["12", "10.1", "-3.3"])
Insert cell
Insert cell
total2017 = d3.sum(
plastics.filter(d => d.date.getFullYear() === 2017),
d => d.weight
)
Insert cell
total2018 = d3.sum(
plastics.filter(d => d.date.getFullYear() === 2018),
d => d.weight
)
Insert cell
Insert cell
Insert cell
plastics.reduce((a, b) => a + b.weight, 0) // 🕷 summing numbers and strings
Insert cell
plastics.reduce((a, b) => a + Number(b.weight), 0) // 🕷 summing numbers and NaN
Insert cell
Insert cell
typedArray = Float32Array.from({length: 100}, Math.random)
Insert cell
d3.sum(typedArray)
Insert cell
Insert cell
plastics = d3.csvParse(`source,target,date,value,weight
CAN,CHN,2017-01,2042849,3423283
CAN,CHN,2017-02,2393816,3733950
CAN,CHN,2017-03,2485664,4016028
CAN,CHN,2017-04,2209183,3612766
CAN,CHN,2017-05,1547378,2404447
CAN,CHN,2017-06,1132445,1649834
CAN,CHN,2017-07,1152219,1471140
CAN,CHN,2017-08,1570572,2493531
CAN,CHN,2017-09,1011581,1784623
CAN,CHN,2017-10,296837,509689
CAN,CHN,2017-11,159765,309563
CAN,CHN,2017-12,78009,138558
CAN,CHN,2018-01,178065,295907
CAN,CHN,2018-02,349891,280870
CAN,CHN,2018-03,47183,84043
CAN,CHN,2018-04,80656,116881
CAN,CHN,2018-05,18522,28397
CAN,CHN,2018-06,49900,53988
CAN,CHN,2018-07,15417,24211
CAN,CHN,2018-08,9128,7472
CAN,CHN,2018-09,2281,1855
CAN,CHN,2018-10,16340,27573
CAN,CHN,2018-11,22374,45643
CAN,CHN,2018-12,N/A,N/A`, d3.autoType)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more