Can I set the number of ticks on the yAxis of a barchart?

3,029 views
Skip to first unread message

Becky Boes

unread,
Jul 25, 2013, 6:22:40 AM7/25/13
to dc-js-us...@googlegroups.com
I've been using dc.js for several months and love it!  Thanks for all your efforts.

I am building barcharts that are very small - for example, one is 120px high and 140px wide.  They are all rendered with the DEFAULT_Y_AXIS_TICKS (=5) and all of the tick mark labels are scrunched together.  I tried to change the number of ticks using

chart.yAxis().ticks(3)

but nothing changed.  Modifying yAxisPadding helped a bit, but raised the graph above the x-axis. I was able to get it to work by adding a _yTicks method and modifying prepareYAxis() in the coordinateGridChart but would prefer not to touch the core code.  Is there another way to do this?

Thanks,
Becky

Nick Zhu

unread,
Jul 25, 2013, 11:24:01 AM7/25/13
to Becky Boes, dc-js-us...@googlegroups.com
dc.js use d3 axes directly so you can use anything that works for d3 axes. The ticks function on d3 axes does not force the ticks but rather serve as a hint for d3 so if you want complete control over how ticks should be generated try https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-tickValues function instead.
Reply all
Reply to author
Forward
0 new messages