-->

How to change tick's text with ordinal axis

2019-07-24 10:13发布

问题:

I have chart with next properties:

barChart
       .width(width)
       .height(height)
       .dimension(dim)
       .group(group)
       .x(d3.scale.ordinal())
       .xUnits(dc.units.ordinal)

My axis tick looks like "ZZxBob", "PxBob"

How to use split function by 'x' to each tick?

回答1:

The axes are generated entirely by D3.

You can use chart.xAxis() to retrieve the x axis object, and then axis.tickFormat() to change the way it's displayed.

So, e.g. to display the part before x:

barChart.xAxis()
    .tickFormat(function(l) { return l.split('x')[0]; })


标签: dc.js