score:0
You can use d3.text to load the CSV data, and then iterate over the text to create an array of objects with named values, which could then be stacked or whatever you would normally do in D3 with your data
d3.text("data.csv", function(text) {
console.log(text);
var data = []
d3.csvParseRows(text).forEach(function(row) {
let obj = {}
row.forEach(function(value, i) {
let pairIndex = Math.floor((i - 1) / 2)
//assume first value is the index or name for the row, eg A, B, etc
if (i == 0) {
obj.index = value
}
else if (i % 2 == 0) {
let v = "age2-" + pairIndex
obj[v] = value
} else {
let v = "age1-" + pairIndex
obj[v] = value
}
});
data.push(obj)
});
console.log(data);
// continue with your code
Source: stackoverflow.com
Related Query
- d3 stack on data without header
- d3 - return only data without header
- How do I create a tree layout using JSON data in d3.v4 - without stratify()
- Hide some graphic elements, c3js, without unloading data
- Convert data types in d3.js without prior knowledge of property names (detect if a string contains only digits)
- D3: Using a closure to update a selection without re-binding data
- Fetch JSON data using Authorization header in D3 v5
- How to update data in stack bar chart in D3
- d3js stack chart with simple data
- Use d3 stack layout with data organized per points, instead of per layers
- Data file with illegal column names, reading header as keys
- Unable to reference d3.js data imported from a csv file with spaces in the header
- Accessing multi-dimensional data without a for loop to make arc data along radial
- How to get SVG path data of TopoJSON feature without adding it to the DOM?
- Stratify flat data without directly specifying parent
- Bar chart: set axis domain from csv without header
- Stack a matrix in d3 without remapping to json
- First data is ignored without using selectAll in d3.js
- D3 - loading data with no header
- d3 choropleth: changing data without reloading map
- D3 stack chart from Array data
- sum up data without specific key name
- How to reshaping Data in Javascript from array to object without losing some of the data
- change label data of node without rendering graph in D3.js
- How to update a single data point in d3 without touching other elements?
- Data transformation for d3 stack
- Parsing header row with dates when importing csv data
- Stack bar chart animated data change
- How can I group data to be filtered without losing crossfilter functionality using dc.js?
- Heavy calculations and displaying data without blocking UI
More Query from same tag
- D3.js-How can I get the maximum value of a specified key in an object
- d3 data manipulation before plotting
- Using d3.nest() with geojson files
- D3.js/Dc.js different colored line segments for single line in line graph
- Add number to transform attribute
- Calculate SVG Path Centroid with D3.js
- How to flatten d3.nest using javascript map() method?
- how to define a static xaxis and y axis, javascript d3
- Reading columns in their order of the csv file
- vuejs + d3: select returns element, but attr() returns null
- Can I update DOM elements in a D3 selector based on a data join to a different data object?
- Make an external Script available to all members of qooxdoo Object
- How to translate svg element along y-axis?
- force directed graph different cluster for different groups
- What's the point of using an anonymous function for a one-liner?
- d3js grouped bar chart, is this possible?
- Is the length of the text in a nvd3-legend adjustable?
- d3.js sorting graph by both axes
- Incorrect appearance of bar positions - d3.js
- Enable scroll on the axis of D3 chart
- D3 Rolling map updates d3.geo.circle, but not arcs
- process cvs data for d3
- What is the best way to match elements by index for update in a Scatter plot?
- Circle-packing diagram - transition between two set of values
- Get Clipped Line Visible Area Length d3
- d3js stack chart: how to add text on each layer?
- Style specific text in D3.js
- Is there a function to find the approximate x and y co-ordinate values on a line chart using D3.js?
- rid3, shadow-cljs & drag; different behavior in dev and prod
- d3 setinterval animate text and remove image on button click