I am trying to reuse some code that makes x-axis ticks. Here is the method I've put it in:
xTicks: (scale, dayTickFormat) ->
d3.svg.axis().scale(scale).orient("bottom")
.ticks(d3.time.days, 1)
.tickSize(10)
.tickFormat(dayTickFormat)
.tickPadding(8)
Please pardon the coffeescript :\\
Anyway, I here is the code that calls that:
drawTicks: (chart, chartOptions, margin, x, y, num_y_ticks) ->
xTickGroup = chart.append("g").attr("class", "day-ticks")
.call(@xTicks.bind(@, x, dayTickFormat))
.attr("transform", "translate(#{chartOptions.offset.left}, #{chartOptions.height - 10})")
When this code executes, I don't get any ticks. I'm stumped. Any thoughts?
OK, nvm, I got it.
call() wasn't calling the "d3.svg.axis()" bit, it was calling the method I had wrapped around it. So, if I store my method in a variable like so:
xTicks = @xTicks(x, dayTickFormat)
I can call it more simply like this:
xTickGroup = chart.append("g").attr("class", "day-ticks")
.call(xTicks)
.attr("transform", "translate(#{chartOptions.offset.left}, #{chartOptions.height - 10})")
Hope this helps someone, someday :\\
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.