Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3.scale.linear() vs d3.scaleLinear()

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.

like image 899
jack blank Avatar asked Mar 12 '16 04:03

jack blank


People also ask

What is scale linear in D3?

The d3. scaleLinear() method is used to create a visual scale point. This method is used to transform data values into visual variables.

What is a D3 scale?

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.

What will be the output of scale 300 )?

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.

What does range in linear scale describe?

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.


1 Answers

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

like image 90
Hina Dawood Avatar answered Oct 04 '22 03:10

Hina Dawood