c3 icon indicating copy to clipboard operation
c3 copied to clipboard

force line break in x axis tick text

Open daviestar opened this issue 12 years ago • 9 comments

Hey

http://jsfiddle.net/gbdtjsba/11/

I have fairly long labels in my graph. I have added a hard height of 500px to the graph, and 200px to the x axis which works, but I'd like to make the axis height dynamic if possible.

Should I loop through the labels to find the largest one and calculate it's width before applying the graph, or does c3 have a feature which can do this?

Might be related to this one: https://github.com/masayuki0812/c3/issues/527

Thanks for a great library, so far it has saved me many hours of d3 programming :)

daviestar avatar Oct 17 '14 14:10 daviestar

Hi, Thank you for your reporting. I think this commit enables to calculate x axis height automatically, so could you try the latest code again? Thanks.

UPDATE: I introduced axis.x.tick.width to support multiple lines tick text, so please set this option null at this moment. Without this, the tick text will be splitted to multiple lines even if they are rotated.

masayuki0812 avatar Nov 03 '14 07:11 masayuki0812

Hello,

Thanks for your update, unfortunately I don't think it's working -

  1. http://jsfiddle.net/gbdtjsba/15 - Without the 200px x axis height (which I am trying to remove), the results are the same as before. Try resizing the graph to see inconsistent behaviour.
  2. http://jsfiddle.net/gbdtjsba/11 - On load the x axis appears to have the wrong height, but this is fixed when you resize. This version still has 200px height on x axis, and I think it is reverting to this height, not a calculated one.

I think what needs to happen is, for example, the graph has 500px height, the axis ticks have a maximum width/height of 125px, so the chart is automatically given height 375px and labels 125px. Or, if you prefer / as an option, the ability to make the graph height 500px, and the overall height including labels becomes 625px.

Labels on 1+ lines is great. Is it possible to force line breaks? For example 2014-10-22 \n 2014-10-15 \n 2014-10-08?

daviestar avatar Nov 05 '14 14:11 daviestar

It seems not woking in fiddles.. How about on actual code? It works for me. And please set axis.x.tick.multiline = false to show as one line. Now multiline is default.

I think it seems reasonable to introduce something to force line breaks. I'll implement if needed.

masayuki0812 avatar Nov 09 '14 05:11 masayuki0812

I think it seems reasonable to introduce something to force line breaks. I'll implement if needed.

Yes. Needed.

format1981 avatar Dec 01 '14 13:12 format1981

any plans for this?

laurabrooks avatar May 31 '18 15:05 laurabrooks

@laurabrooks I'm not sure what you're referring to with "this", but axis.x.tick.multiline has been implemented for a while and I recently introduced support for axis.x.tick.multilineMax and added documentation for both (see here), hopefully that helps.

jcsmorais avatar May 31 '18 21:05 jcsmorais

I was wondering about forcing a line break at a specified point in label text. multiline and multilineMax attributes will do the job though, thank you for the response @jcsmorais

laurabrooks avatar May 31 '18 21:05 laurabrooks

Hey is there any provision for multiline axis labels?

sibasishm avatar Oct 01 '18 07:10 sibasishm

I'm closing this issue because multiline options already exist. Please refer to the docs which were stated by @jcsmorais.

GDFaber avatar Apr 11 '20 16:04 GDFaber