score:0
You probably want to name and organize your data following what d3.hierarchy
is expecting, look at documentation here
The returned node and each descendant has the following properties:
node.data - the associated data, as specified to the constructor. node.depth - zero for the root node, and increasing by one for each descendant generation. node.height - zero for leaf nodes, and the greatest distance from any descendant leaf for internal nodes. node.parent - the parent node, or null for the root node. node.children - an array of child nodes, if any; undefined for leaf nodes. node.value - the summed value of the node and its descendants; optional, see node.sum and node.count.
So your data should be like:
let data = {
name: 'root',
children: [{
name: 'foods A',
children: [
{
name: 'fruits',
children: [
{ name: 'Apple', size: 1 },
{ name: 'Banana', size: 1 },
{ name: 'Orange', size: 3 },
],
label: 'fruits',
size: 3,
}]},
{
name: 'foods B',
children: [
{
name: 'vegetables',
children: [
{ name: 'Potato', size: 2 },
{ name: 'Carrot', size: 4 }
],
label: 'vegetables',
size: 2
}]
}]
}
Source: stackoverflow.com
Related Query
- How to use d3.js Hierarchy with custom data structure?
- D3: use nest function to turn flat data with parent key into a hierarchy
- How to use the quantize function with my json data file
- how to convert data selected from a postgres database to json or csv to use it with d3js lib?
- "Cartograms with d3 " how to use data from MySQL?
- How do I structure the Data array for the following d3 chart, in order to populate with real data
- How to use attr fill with scalesqrt using data from another json file?
- How do I use MongoDB data with D3 and Node?
- How do I use JSON and return data with D3
- How to use .defer with an internal data object d3 topoJSON map?
- How to use this data with D3js Scatter Plot?
- In D3, how to use SVG files as DOM objects with bound data and paths still exposed?
- How to use custom Angular filter inside directive with D3
- How to add all data to my array to use with a color scale?
- How to use d3.js chart with data from coingeckoapi (json)
- How to use NVD3 with rCharts in R with non numeric data
- D3.js how to use hierarchical layouts with embedded non hierarchical data
- how to deal with unique data use d3.js?
- How to use D3 selectAll with multiple class names
- D3 - how to deal with JSON data structures?
- How to layout a non-tree hierarchy with D3
- How to handle layers with missing data points in d3.layout.stack()
- How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
- how to encode this data to parent / children structure in JSON
- How to use 'this' in Angular with D3?
- How to update d3.js bar chart with new data
- How to show c3.js No data but with legend for empty column?
- How do I load JSON data synchronously with d3.js?
- How to pull data from mysql database and visualize with D3.JS?
- How to put text data with d3.js
More Query from same tag
- Transition not working d3
- D3 shift ticks to align with axis
- Canvas image data on retina display (MPB)
- ServiceNow / GlideRecord - how to prepare data for chart after query the table?
- halven d3 pie chart
- different nvD3 approaches
- D3.js adding draggable circles not working when adding single
- Slow performance in Firefox for D3 force layout
- D3 General update pattern transition not working on pie chart
- How to Create different kinds of grid lines using D3 in the same graph
- How do I draw line from the outer most arc of the circle
- D3 force layout data doesn't update
- typescript import function from 3rd party declare module
- Creating heatmap of states in Brazil
- NVD3 reuse values in multiple group charts
- Select SVG elements by making a free-hand drawing around them
- Rotate svg in place using d3.js
- Fade in bars one by one with D3
- d3.js donut chart with legend outside donut
- how can i hide the names of ancestors of a node
- How do I move tooltip text on a link?
- With nvd3.js/d3.js, how can you have a scatter or line chart with discrete/non-numeric/non-time-series X-Axis values?
- d3 v5: How to transition only when a specific attribute changed?
- Map Filtered JSON Links to Filter JSON Nodes
- Draw special line with js framework
- Converting seconds to minutes and formatting axes
- Shorten SVG path arc by pixel
- How to properly calculate width for D3 Siluohette stacked Area chart
- How to use d3.csv to load variable instead of file?
- D3.js - How to solve NAN error while dragging the line graph (Jsfiddle provided)