Multiline XYTextAnnotation
-
- Posts: 21
- Joined: Thu Sep 29, 2005 4:11 pm
Multiline XYTextAnnotation
I want to be able to use line wrapping/new lines in XYAnnotations. I want to add statistical annotation options for the user in our application that could be 5-6 lines; however, using html or newline characters in the text doesn't work.
Is adding multiline tooltips currently a possibility, or would I have to work out a way to add another XYAnnotation for each line while adding or subtracting a certain number of pixels?
Is adding multiline tooltips currently a possibility, or would I have to work out a way to add another XYAnnotation for each line while adding or subtracting a certain number of pixels?
Newline characters don't work indeed, but HTML code works fine with me:
Code: Select all
<html><body>first line<br>second line</body></html>
-
- Posts: 21
- Joined: Thu Sep 29, 2005 4:11 pm
Thanks Allamistakeo.
I used the string you gave in order to test JFreeChart but when I add a new XYTextAnnotation("<html><body>first line<br>second line</body></html>", x, y); the string is placed exactly as stated on the chart. No formatting.
Is this version specific, or do you have to set a specific property? I am using 1.0 RC2
I used the string you gave in order to test JFreeChart but when I add a new XYTextAnnotation("<html><body>first line<br>second line</body></html>", x, y); the string is placed exactly as stated on the chart. No formatting.
Is this version specific, or do you have to set a specific property? I am using 1.0 RC2
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I think the HTML will work in a tooltip, but not the XYTextAnnotation. It probably wouldn't be too hard to modify XYTextAnnotation to use multiple lines. Patches are welcome, as long as they maintain backwards compatibility of course.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Multiline XYTextAnnotation
Did anyone ever fix this?
I need to pass in multiline Labels to XYPointerAnnotation.
I need to pass in multiline Labels to XYPointerAnnotation.
Re: Multiline XYTextAnnotation
I'm trying to do this too... any resolution or answers here?
Thanks,
Robert
Thanks,
Robert
Re: Multiline XYTextAnnotation
I messed around with this for a while before I finally came across XYTitleAnnotation. This will place a multi-line annotation in the upper left corner of the plot.
Code: Select all
TextTitle textTitle = new TextTitle("first line\nsecond line", new Font(Font.SANS_SERIF, Font.PLAIN, 8), Color.BLACK, RectangleEdge.TOP, HorizontalAlignment.LEFT,
VerticalAlignment.TOP, new RectangleInsets(2, 2, 2, 2));
XYTitleAnnotation xyTitleAnnotation = new XYTitleAnnotation(0, 1, textTitle, RectangleAnchor.TOP_LEFT);
plot.addAnnotation(xyTitleAnnotation);
-
- Posts: 8
- Joined: Tue Jun 23, 2015 2:37 pm
- antibot: No, of course not.
Re: Multiline XYTextAnnotation
I found this class yesterday (https://github.com/JeremyMcCormick/jfre ... ation.java) and added TextAnchor support in a fork:
https://github.com/rivella50/jfreechart ... ation.java
Works perfectly for me:

https://github.com/rivella50/jfreechart ... ation.java
Works perfectly for me:

Re: Multiline XYTextAnnotation
Hi,
had the same problem. Solved it by adding an annotation for each line manually. Here is a quick fix:
Seems to work fine for me.
Cheers,
had the same problem. Solved it by adding an annotation for each line manually. Here is a quick fix:
Code: Select all
private void addMultilineTextAnnotations(double x, double y, String label, Color color) {
String[] lines = label.split("\n");
for(int i=0; i < lines.length; i++){
XYTextAnnotation annotationLabel = new XYTextAnnotation(lines[i],
x, y - (i+1) * XYTextAnnotation.DEFAULT_FONT.getSize());
annotationLabel.setPaint(color);
plot.addAnnotation(annotationLabel);
}
}
Cheers,