quantumpotato
quantumpotato

Reputation: 9767

d3 layout is undefined

Trying to use d3.js and not sure how to reference it properly:

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="jquery-1.7.1.js"></script>
<<<<other scripts>>>
<script src="topbar.js"></script>
<script>
$(function() {
    var n = 4, // number of layers
        m = 64, // number of samples per layer
     data = d3.layout.stack()(stream_layers(n, m, .1)),
    color = d3.interpolateRgb("#aad", "#556");
});
</script>
</head>
...
</html>

Upvotes: 12

Views: 25767

Answers (3)

Tweak3r
Tweak3r

Reputation: 221

You should use d3.stack instead.

Every symbol in D3 4.0 now shares a flat namespace rather than the nested one of D3 3.x. For example, d3.scale.linear is now d3.scaleLinear, and d3.layout.treemap is now d3.treemap.

For other d3.layout changes go here: https://github.com/d3/d3/blob/master/CHANGES.md

Upvotes: 21

gfjr
gfjr

Reputation: 1388

(it's not the answer for this question)

For the people with the same error:

d3.layout is undefined

In my case was the problem I just link directly to the latest release (v4)
https://d3js.org/d3.v4.min.js

With (v3) it is working again.
https://d3js.org/d3.v3.min.js

Upvotes: 8

mbostock
mbostock

Reputation: 51829

You need to include d3.layout.js in addition to d3.js; the layout module is in a separate file by default. You can also make a custom build of d3.js that includes everything you need in a single file.

Upvotes: 25

Related Questions