Hi I'm looking at the documentation for scales and it shows a format like this var x = d3.scaleLinear([10,130]).range([0,960])
I feel like this is strange because most examples that I see online use something like this:
var x = d3.scale.linear().domain([10,130]).range([0,960])
and it works.
If I use var x = d3.scaleLinear([10,130]).range([0,960]);
I get an error like
TypeError: d3.scaleLinear is not a function
Why do you think there is a discrepancy between the examples in the documentation and what I see in examples online? maybe I don't understand how to read documentation.
EDIT : This is the current documentation for scales.
To create a linear scale with d3.js version 3 use API
d3.scale.linear()
and to create a linear scale with version 4 and 5 use API
d3.scaleLinear()
API references for creating a linear scale for both the versions can be found here:
v3.x scale.linear
v4.x scaleLinear
As specified by Hina, d3.scale.linear() is used on D3 3.0, and d3 4.0 adopted the flat namespace convention. Here is a snippet from the d3 changelog summary
Source: https://github.com/d3/d3/blob/master/CHANGES.md
EDIT: Forgot to mention - to fix your error, you may have to update the link or file to d3 that you have in your program. I call it directly from the website with:
The documentation you're looking at is for a plugin for D3 -- how to install it is described further down on that same page. It will eventually be part of the next major release of D3.
They are doing exactly the same thing, but it's just code change happen to
D3.js
from version 3 to version 4...So linear is not property of scale object of d3 framework anymore...
instead it's part of d3 with camelCase syntax...
So
d3.js
v3 used3.scale.linear()
and to create a linear scale with v4 use
d3.scaleLinear()
instead...version 3:
version 4: