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");
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.
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.
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.
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.
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).
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