Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  49] [ 3]  / answers: 1 / hits: 22426  / 8 Years ago, tue, august 9, 2016, 12:00:00

For some reason I am getting d3.scale is undefined. D3 is properly loaded; I'm using the one listed on the main d3js.org site here.



My JS file handling the D3 code:



InitiateChart_1();

function InitiateChart_1()
{
var data = [5,10,15,20,25];
var height = 500, width = 500;

var xScale = d3.scale.linear()
.domain([0,60])
.range([0,width]);

var canvas = d3.select(body)
.append(svg)
.attr(id,chart1)
.attr(width,width)
.attr(height,height);

var bars = canvas.selectAll(rect)
.data(data)
.enter()
.append(rect)
.attr(height,10)
.attr(width,function(d){return xScale(d);})
.attr(y,function(d,i){return i * 12;})
}


My entire HTML file:



<!doctype html>
<html>
<head>
<title>SHED Report Prototype</title>
<meta charset='utf-8'>
<script src=https://d3js.org/d3.v4.min.js></script>
</head>
<body>
<script src='js/studentloans.js'></script>
</body>
</html>


Any help is greatly appreciated.


More From » html

 Answers
24

The codepen is using version 3; this code uses version 4 of the api. d3.scale.linear has become d3.scaleLinear.




[...] However, there is one unavoidable consequence of adopting ES6 modules:
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. [...]




-https://github.com/d3/d3/blob/master/CHANGES.md
(emphasis mine)


[#61083] Sunday, August 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;