chartist icon indicating copy to clipboard operation
chartist copied to clipboard

X axis label position when point count changes

Open kirkbross opened this issue 7 years ago • 3 comments

I'm using Chartist bar chart in a ReactJS app with a date range filter to change the range.

When I switch from a 30 day view to a 7 day view, I need to keep the X axis label under the bar.

See these pics:

30days 7days

.ct-label.ct-horizontal { white-space: nowrap; -webkit-transform: rotate(60deg); -moz-transform: rotate(60deg); -ms-transform: rotate(60deg); -o-transform: rotate(60deg); transform: rotate(60deg); transform-origin: 15px 7px !important; height: 18px !important; width: 50px !important; }

kirkbross avatar Jan 19 '18 01:01 kirkbross

Well... I managed to achieve my goal with a left-margin: calc(50% - 9px); but it seems like the is probably a better, native way of centering the label under the bar.

kirkbross avatar Jan 19 '18 02:01 kirkbross

Are you using foreignObject or text (depends on client capability) – ?

I have a similar issue where it helps wrapping the text node in an svg node – transferring the positioning and width to the svg element and setting x="50%" along with text-anchor: middle on the text.

But I am not sure how that works with label rotation.

malthe avatar Feb 18 '18 10:02 malthe

Hello @kirkbross 👋

Chartist has recently been updated to version 1.0 with some new exciting changes like ESM and TypeScript support. The migration guide can be found right here.

Please let me know if the quiestion is still relevant to you so we can further look into it!

Arantiryo avatar Oct 30 '22 11:10 Arantiryo