Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'd3.svg.axis()' in d3 version 4?

Tags:

d3.js

How can I replace below lines with the new version of D3 API?

I have already replaced scale.linear() with scaleLinear()

var xRange = d3.scaleLinear()     .domain([OIResults.min,OIResults.max]).range([40, 360]);  var yRange = d3.scaleLinear()     .domain(y_domain).range([360, 40]); 

Below Lines need to be replaced according to the new API:

var xAxis = d3.svg.axis().scale(xRange).tickFormat(function(d) { return d.x;}); var yAxis = d3.svg.axis().scale(yRange).orient("left"); 
like image 917
Vijay Kumar Singh Avatar asked Nov 07 '16 12:11

Vijay Kumar Singh


People also ask

What is d3 js axis component?

Advertisements. D3 provides functions to draw axes. An axis is made of Lines, Ticks and Labels. An axis uses a Scale, so each axis will need to be given a scale to work with.

What is a tick in d3?

ticks should be a format specifier string; see d3. format. If the format specifier does not have a precision, the scale will chose an appropriate precision based on the interval between ticks. This guarantees that each tick has a distinct label, and that each label is formatted concisely but consistently.

What is domain and range in d3?

The domain is the complete set of values, so in this case that is all of your temperatures, from 33 to 64. The range is the set of resulting values of a function, in this case the resulting values of scaling your temperatures from 0 to 600.

Which is not a valid scale in d3 JS?

If input is greater than 10 or less than 0 in domain or the range is greater than 600 then it is not a valid scale in d3 js.


1 Answers

The D3 v4 API is here. According to the changelog:

D3 4.0 provides default styles and shorter syntax. In place of d3.svg.axis and axis.orient, D3 4.0 now provides four constructors for each orientation: d3.axisTop, d3.axisRight, d3.axisBottom, d3.axisLeft.

Therefore, those lines should be:

var xAxis = d3.axisBottom(xRange).tickFormat(function(d){ return d.x;}); var yAxis = d3.axisLeft(yRange); 

PS: I'm assuming that you want the ticks to be below the axis, which is normally the case, since you didn't show the orient in your original lines.

PPS: At the time of the writing the linked documentation applies to D3 v4. Caveat, lector: that can change at any time (see comments below).

like image 60
Gerardo Furtado Avatar answered Oct 04 '22 02:10

Gerardo Furtado