9 Mar 2010 8:58 AM #1
YAxis label width
YAxis label width
I have a horizontal bar chart that is dynamic: it starts out empty and I add bars over time. The labels for the bars are unknown until the data arrives. That means as each bar and its label are added, the size of the chart changes each time a label is added that is longer than a previous label. What I'd like to do is set all the labels to a default value consisting of, say 15 non-breaking spaces, then replace them with regular text as data arrives.
So, my question is, is there a way to set the value of YAxis labels to a set number of white space characters? I've been trying things like %20 and , and haven't been able to make it work.
Thanks in advance for any suggestions.
10 Mar 2010 6:25 PM #2
Are there any other suggestions for keeping the width of the chart constant when adding new bars and labels dynamically?
I thought there must be a way to set the labels with a large number (e.g., 15) of white space characters, but since I haven't gotten any replies, maybe it's not that easy.
11 Mar 2010 9:02 PM #3
If you want to add spaces to the with of the YAxis labels just add spaces to the string.
List<String> labels = new ArrayList<String>();
labels.add(" " + someMinLabel);
labels.add(" " + someMaxLabel);
12 Mar 2010 4:30 AM #4
Thanks for replying, but it's not quite that simple. Here's the problem: I start out with a horizontal bar chart containing no bars and no labels. At startup, the chart takes up the entire space, i.e., the label area is compressed to nothing. When I add the first data point, a label is added, so the width of the chart decreases to accommodate it. Then, every time I add a new bar, the width of the chart will decrease if the new label length is greater than the previous label length. I'd like the chart to start out with a reasonable width reserved for labels, and not be changing width as I add data.
And, as near as I can tell, the labels show the typical html behavior of ignoring extra white space above a single space. So, I couldn't decide all the labels should be 15 characters long and pad each one with the calculated extra spaces. Also, I tried adding codes instead of spaces, and they showed up as in the labels.
14 Mar 2010 3:12 PM #5
15 Mar 2010 5:37 PM #6
When you're right, you're right. I was starting off initializing all the labels with strings composed entirely of spaces, and in that case, the spaces were ignored and the chart took up the entire space until I updated one of the labels with some non-space characters. Once I get the first real label in, the extra space padding works, as you pointed out.
So, my solution to the initialization problem is to set the first label to something like this : "------------------" and set the label color to white. Then when the first real data arrives, I update the label text and set the color to black.
Thanks for getting me to take another look.