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.
The d3. scaleLinear() method is used to create a visual scale point. This method is used to transform data values into visual variables.
D3 scale types D3 has around 12 different scale types (scaleLinear, scalePow, scaleQuantise, scaleOrdinal etc.) and broadly speaking they can be classified into 3 groups: scales with continuous input and continuous output. scales with continuous input and discrete output. scales with discrete input and discrete output.
It means scaling factor is 0.5 and the data will be represented in pixels as: data value * 0.5. So, now if our input value is 300, the output value would be 150.
A scale's range, on the other hand, describes the set of possible output values that the input values can be converted to. If we're building a bar chart to display our test scores, we'd want our range to describe the minimum and maximum bar sizes.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With