Here is a fairly rough and ready fix that allows you to print a line of text anywhere in the chart (except in the area used by the plot - use an annotation for that). It involves a couple of extra methods in JFreeChart.java and one new class in org.jfree.chart.title. It's based on the methodology for implementing subtitles in the chart.
1) Patch to src/org/jfree/chart/JFreeChart.java
Code: Select all
146a147,149
> import org.jfree.chart.title.Note;
> import org.jfree.text.TextBlock;
> import org.jfree.text.TextLine;
206a210,212
> /** The chart notes (zero, one or many). */
> private List notes;
>
300a307
> this.notes = new ArrayList();
457a465,473
> * Returns the list of notes.
> *
> * @return the note list.
> */
> public List getNotes() {
> return this.notes;
> }
>
> /**
512a529,539
> * Adds a chart note.
> *
> * @param note the note.
> */
> public void addNote(Note note) {
> if (note != null) {
> this.notes.add(note);
> }
> }
>
> /**
879a907,913
> // draw any notes
> Iterator noteIterator = this.notes.iterator();
> while (noteIterator.hasNext()) {
> Note currentNote = (Note) noteIterator.next();
> drawNote(currentNote, g2, nonTitleArea);
> }
>
983a1018,1032
> /**
> * Draws a note. A note is an arbitrary piece of text which can be
> * placed anywhere in the chart area. The note contains the text
> * to be written, the font and color to use and its x,y
> * coordinates.
> *
> * @param note the note to place (<code>null</code> not permitted).
> * @param g2 the graphics device (<code>null</code> not permitted).
> * @param area the chart area, excluding any existing titles (<code>null</code> not permitted). */
> public void drawNote(Note note, Graphics2D g2, Rectangle2D area) {
> TextBlock tb = new TextBlock();
> tb.addLine(new TextLine(note.text, note.font, note.paint));
> tb.draw(g2, note.xCoord, note.yCoord, null);
> }
>
2) Add new class, Note.java to src/org/jfree/chart/title/
Code: Select all
package org.jfree.chart.title;
import java.awt.Font;
import java.awt.Paint;
/**
* An arbitrary piece of text which can be placed anywhere in the
* chart area. The coordinates are given in pixels with (0,0) at
* the top-left of the chart. Note that the plot area overwrites any
* notes so if you need text inside the plot, use an Annotation
* instead.
*/
public class Note {
/** The text to be printed in the note */
public String text;
/** The font to be used for the note */
public Font font;
/** The paint (ie, color) to be used for the note */
public Paint paint;
/** The x-coordinate of the note (in pixels) */
public int xCoord;
/** The y-coordinate of the note (in pixels) */
public int yCoord;
/**
* Constructs a Note - A note is an arbitrary piece of text which
* can be placed anywhere in the chart area.
*/
public Note (String text, Font font, Paint paint, int xCoord, int yCoord) {
this.text = text;
this.font = font;
this.paint = paint;
this.xCoord = xCoord;
this.yCoord = yCoord;
}
}
3) To demo; add this patch to src/org/jfree/chart/demo/TimeSeriesDemo.java
Code: Select all
> import java.awt.Font;
> import org.jfree.chart.title.Note;
106a112,113
> chart.addNote(new Note("Banana", new Font("Helvetica", Font.PLAIN, 10), Color.black, 5, 5));
Rgds,
Oscar