I am using d3.time.scale to generate x-axis, and the domain ranges from 1980 to 2013 (year) However, tick value only displays upto 2012, not 2013.
I tried .ticks(), but the final tick value does not display until tick count is 25...
Although I can add the final value by manually increasing the domain upto 2014, is there a way to display the tick value for the last tick?
xAxis = d3.svg.axis()
.scale(xScale).tickSize(20)
var maxYear = format.parse('2014')
xScale = d3.time.scale().domain([min,max])
.range([100,width-200]) //domain = [1980 ~ 2013]
var min = d3.min(data, function(d) {
return d.Year; // + operator converts string to number.
})
var max = d3.max(data, function(d) {
return d.Year;
})
Thank you in advance.
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 d3. scaleLinear() method is used to create a visual scale point. This method is used to transform data values into visual variables.
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.
d3. range returns an array of evenly-spaced numbers. In its simplest form, it returns the integers from zero to the specified end minus one. Array(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Have you tried using .nice()
?
https://github.com/d3/d3-scale/blob/master/README.md#time_nice
This should do the job:
xScale = d3.time.scale().domain([min,max])
.range([100,width-200]) //domain = [1980 ~ 2013]
.nice()
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