score:12
The force-directed layout uses edge weights to calculate the layout. Try adding a dummy "weight":1
to all of your connections.
The code that initializes the links looks like this:
links.forEach(function(d) {
if (typeof d.source == "number") { d.source = nodes[d.source]; }
if (typeof d.target == "number") { d.target = nodes[d.target]; }
});
Presumably you could tweak that (in the d3 source) to use any property/type.
score:2
I've had this issue pop up in a number of ways. Most recently, I had my edge list as follows:
{Source: 0; Target: 1}
instead of:
{source: 0, target: 1}
score:5
I think you might have null values in your source and target. I had this bug too and fixed it by filtering out the null values.
score:10
Thanks to the answers above which refer to null source or target values!
I've been testing out the graph from http://bl.ocks.org/mbostock/4062045, and found that my data referenced a missing node.
This may help others debug this issue:
d3.json("my-buggy-data.json", function(error, graph) {
// Find blank links, which give the error
// "Uncaught TypeError: Cannot read property 'weight' of undefined"
graph.links.forEach(function(link, index, list) {
if (typeof graph.nodes[link.source] === 'undefined') {
console.log('undefined source', link);
}
if (typeof graph.nodes[link.target] === 'undefined') {
console.log('undefined target', link);
}
});
force
.nodes(graph.nodes)
.links(graph.links)
.start();
score:12
In addition to the answers mentioning the null in the source/target of links, the reason for this could be the assignment of an out-of-range source/target. E.g. you have 10 nodes and you assign the target to be the 11-th indexed node.
score:18
I encounter same problem before, it is due to there is null values in source/target of links. print out nodes and links information might help to debug
Source: stackoverflow.com
Related Query
- d3.js: "Cannot read property 'weight' of undefined" when manually defining both nodes and links for force layout
- Cannot read property 'push' of undefined when refactoring code
- Error when generating line Chart, Uncaught TypeError: Cannot read property 'each' of undefined
- Cannot read property 'push' of undefined when refactoring code, part 2
- Uncaught TypeError: Cannot read property 'linear' of undefined
- d3.svg.line() error: Uncaught TypeError: Cannot read property 'line' of undefined
- C3JS - Cannot read property 'category10' of undefined
- D3.js - Cannot read property 'axis' of undefined
- D3.js : Uncaught TypeError: Cannot read property 'document' of undefined
- Uncaught TypeError: Cannot read property 'arc' of undefined in AngularJS and D3
- Cannot read property 'force' of undefined (Simple D3 Network graph)
- NVD3 Line Chart Uncaught TypeError: Cannot read property 'x' of undefined
- D3 Zoom Cannot read property 'transform' of undefined
- Cannot read property 'drag' of undefined D3
- TypeError: Cannot read property 'childNodes' of undefined angular
- Cannot read property 'weight' of undefined in d3.force implementation
- topojson.js:187: Uncaught TypeError: Cannot read property 'type' of undefined
- Uncaught TypeError: Cannot read property 'axis' of undefined
- Uncaught TypeError: Cannot read property 'albersUsa' of undefined
- d3.js - Uncaught TypeError: Cannot read property 'data' of undefined
- TypeError: Cannot read property '1' of undefined D3.js
- Datamaps is giving me a Cannot read property 'albersUsa' of undefined
- Cannot read property 'getHours' of undefined
- NV.D3 Cannot read property 'length' of undefined
- topojson/d3.js: Uncaught (in promise) TypeError: Cannot read property 'type' of undefined
- d3 Cannot read property 'classed' of undefined
- Error on mouse down when using d3-brush: Cannot read property 'touches' of null
- Uncaught TypeError: Cannot read property 'type' of undefined with d3.js
- 'd3.nest()' cannot read property of undefined
- Trouble Shooting Cannot Read Property 'length' of Undefined
More Query from same tag
- Simple circle animation is only displayed the first time
- How to create a custom color scale?
- Using d3.js with Apache Zeppelin
- Why can't i see this d3 bar chart in an angular directive?
- Properly show aliased legend items in dc.js (glitchless transitions)
- Existing Triangles Cannot be Removed
- d3.js : Differentiate between drag/start/end and click event
- d3-venn / venn.js Venn Circles are coming out enclosed within each other
- d3 tooltip bar for multi line chart on mouseover on Y Axis (code supplied)
- Simple d3.js graph with a json feed input
- Should I use d3.js to draw lines between paragraphs of text?
- Adding Dynamic Attr() to d3.tip
- force directed graph - why pointers change size along with the link width
- How to make multiple charts with d3.chart using nested data
- Change time intervals after zooming
- d3.js updated rect keeps previous one
- d3.js barchart not quite like I want it
- How to draw a JSON list in D3.js?
- Pie (donut) chart tooltips
- Questions when building bar charts by D3.js
- How to draw bar chart with range x-axis?
- Assume value 0 on days with no data (C3js time series chart)
- D3 y-axis percent display
- D3 Only Loading One Cell of Data
- D3 - Can't get popover to appear at cursor xy coordinate
- Pie Chart does not update after first click? onClick works only for first time
- D3.js: How to change the position of a text in one single node
- How to use d3.js colorScale to change color based on string values rather than numeric values?
- On change event on d3.js library duplicate charts
- source code in tickSize d3.js v4