Hi,
Does anyone know how to retrieve text content from an AttributedString ?
I'm using the new JFreeChart-FSE API and it uses AttributedString instead of String for the RangeAxis labels. I have set unique labels for the x and y-axis, e.g., my y-axis label is set to "Value (y)". How do I retrieve the text labels, i.e, the string "Value (y)" from the y-axis (i.e., the RangeAxis) ?
The plot.getRangeAxis().getLabel() method now returns an AttributedString and I do not know how to iterate through it and retrieve the label text.
Please help me out.
Thanks.
JFreeChart AttributedString: how to get axis Label ?
Re: JFreeChart AttributedString: how to get axis Label ?
Thanks for the docs.
However, I went through them before posting this question as I still cannot figure out how to get the exact String that is being used in my y-axis' Label. I can get the first character of the "text" attribute using the or get the begin and end indexes but do not know how to get the entire text attribute as a String.
If you have any information about this, do let me know.
Thanks.
However, I went through them before posting this question as I still cannot figure out how to get the exact String that is being used in my y-axis' Label. I can get the first character of the "text" attribute using the
Code: Select all
AttributedString.getIterator().current()
If you have any information about this, do let me know.
Thanks.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: JFreeChart AttributedString: how to get axis Label ?
It's an iterator, so use it to iterate over the AttributedString:
Code: Select all
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.text.CharacterIterator;
public class AttributedStringTest {
public static void main(String[] args) {
AttributedString s = new AttributedString("Hello World");
StringBuilder sb = new StringBuilder();
AttributedCharacterIterator iterator = s.getIterator();
char c = iterator.first();
while (c != CharacterIterator.DONE) {
sb.append(c);
c = iterator.next();
}
System.out.println(sb.toString());
}
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: JFreeChart AttributedString: how to get axis Label ?
Thanks a lot David. That works perfectly.
I was trying to use the .getIterator().getAllAttributes() method of the AttributedString to try and and get all attributes back in a Map (of type <Attribute, Object>) to then iterate over it and get the value for the "text" attribute; but that didn't work.
This works perfectly though.
Thanks.
I was trying to use the .getIterator().getAllAttributes() method of the AttributedString to try and and get all attributes back in a Map (of type <Attribute, Object>) to then iterate over it and get the value for the "text" attribute; but that didn't work.
This works perfectly though.
Thanks.
Last edited by AjitPS on Mon Jul 07, 2014 5:22 pm, edited 1 time in total.
Re: JFreeChart AttributedString: how to get axis Label ?
Hi David, I have a couple of queries around issues that I'm facing with the AttributedString labels of the domain & range axis. Any feedback from you on this would be very helpful. Thanks. The issues are described here:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=116966
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=116966
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: JFreeChart AttributedString: how to get axis Label ?
There is an AttributedStringUtils class in JFreeChart FSE, and it has a toString() method that you can use (maybe I added that after your earlier question?).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program