react-d3-axis icon indicating copy to clipboard operation
react-d3-axis copied to clipboard

Move x axis to the bottom

Open jackdbd opened this issue 7 years ago • 1 comments

Probably this will sound as a really dumb question, but how do I move the x axis to the bottom of a chart?

I tried to use style={{ orient: BOTTOM }}, but that affects only the ticks, not the <g> element of the axis.

<Axis {...axisPropsFromBandedScale(widthScale)} style={{ orient: BOTTOM }} />

Are there any props I can pass to translate the <g> element?

By the way, cool library, I was looking for a way to avoid using refs for d3 axes.

jackdbd avatar Jun 26 '18 18:06 jackdbd

Thanks! This library is pretty low-level -- so you can wrap the <g> with another <g> with a transform to position it in your chart. Something like:

<g transform={`translate(${padding}, ${padding + innerHeight})`}>
          <Axis
            {...axisPropsFromTickScale(xScale, 10)}
            style={{orient: BOTTOM}}
          />
        </g>
        <g transform={`translate(${padding}, ${padding})`}>
          <Axis
            {...axisPropsFromTickScale(yScale, 10)}
            style={{orient: LEFT}}
          />
        </g>

shauns avatar Jun 27 '18 10:06 shauns