score:1
Accepted answer
you want to iterate over the keys in data, use the key to look up the corresponding value in data, and operate on the values.
you want something like this:
d3.json("data/data2.json", function(error, data) {
for (k in data) {
var k_data = data[k];
k_data.foreach(function(d) {
d.date = parsedate(d[0].date);
d.close = +d[0].close;
});
}
});
also, it looks like foreach
takes a function that has two arguments, key
and value
:
foreach: function(f) {
for (var key in this) {
if (key.charcodeat(0) === d3_map_prefixcode) {
f.call(this, key.substring(1), this[key]);
}
}
}
for example:
values: function() {
var values = [];
this.foreach(function(key, value) {
values.push(value);
});
return values;
}
later: ameliabr is correct about foreach
: it is not available for use on objects/dictionaries.
var a = {"stock1": [1, 2, 3, 4], "stock2": [2, 3, 5, 7], "stock3": [1,2, 4,8]};
a.foreach(function(value, key){ console.log(value, key);});
/* typeerror: object #<object> has no method 'foreach' */
but this works:
a["stock1"].foreach(function(value, key){ console.log(value, key);});
1 0
2 1
3 2
4 3
Source: stackoverflow.com
Related Query
- Nested JSON array and D3JS
- d3js roll up a nested JSON array and sum up a total value
- Retrieving keys from a json array file(dynamically) and use it for d3js functions
- d3.js - max and min value from json data which has array of values
- Turn a JSON array of arrays into <ul> and <li> elements
- d3js pie graph from jquery ajax - correlating json keys and values on the chart
- Sum of nested JSON array using D3 .rollup
- How do I access values in a d3 json file with nested array objects
- random number generation and nested array in JavaScript
- D3 nodes and links from JSON with nested arrays of children
- D3 nested select and sibling from json property of object
- D3.js - plotting images with nested array in json
- D3.js moving from tsv to json with nested array
- How do you call data from nested JSON array using d3?
- How to map json data containing an array of datas and one date?
- D3 v4: spacing between and binding of elements of arbitrarily complex array with nested g tags
- How to parse an array of objects using data method of d3js and display it in tool tip?
- Create a table structure in d3js from array of array and draw text or graph
- C3.js - Nested JSON objects, How to access and load data?
- D3.js Heatmap: How to read from a nested json and create a Heatmap using D3
- how to access data from nested json array D3
- d3js - force: nodes and links from json file not loaded in my svg during redrawing
- how can i group JSON data and generate a graph of each group in D3js
- adding values and merging json objects based on key in d3js
- convert multilevel nested array using into json using javascript
- Can't acces Json data and plot line on canvas d3js
- d3js - how to filter the array with values and pass in to data?
- D3 bar graph looking different when using numbers array and json elements array
- Issue with d3js and nested iterations
- How to map over nested D3 objects and create array
More Query from same tag
- Line chart zoom for multiseries d3js v5 chart
- Logarithmic charts in crossfilter
- Using .tsv data in D3
- D3.js: How to reverse a line graph with respect to x-axis?
- How do I implement d3's enter update exit pattern for an area chart with focus and context?
- Locating the nodes according to the coordinates in the json
- Get width of element
- Why my D3.js Dropdown filter is random ?
- How to apply topojson's projection to a voronoi in d3?
- Load Delimiter Separated Values in D3
- Manipulate d3.js pack layout with HTML5 Range Input
- Minor tweaks for histogram generated using d3
- how to stack series in nvd3 multibar angularjs directive
- D3 Bar Chart Graphical Representation Issue
- Add links between gray nodes - Directed Graph Editor d3.js
- d3 interaction between map symbol and a legend box
- d3.js updating from v3 to v5
- dc.js geoChoroplethChart doesn't display legend
- Creating d3 bar chart
- d3.js concentric ring chart
- Issue with D3 zoomable treemap
- ExtJS application build fails: ReferenceError: d3 is not defined
- D3: x-axis with time interval of a year
- selecting deep elements in d3
- Create d3 choropleth dataset
- d3.js transition end event
- Removing line elements in D3
- Slicing data in d3.js
- Append SVG items on top of existing elements
- How to use d3+react?