Multiple Subtitles/Line on Charts
This is a re-submission of a request I made 2 years ago
(SourceForge # 686595 02/14/03).
Background:
This request is crucial to the charts I do. As the
enclosed sample chart (ChartSample.png) shows, I am
required to add a lot of textual data to the charts. The
proposed addition allows me to accomplish this easily.
I have been stuck at Version 0.9.8 because I didnt have
time to keep applying and testing these modifications to
all the interim versions. I recently began updating to the
latest Version (0.9.21, then 1.0.0-pre1, and now 1.0.0-
pre2). I still need this capability!
NOTES:
1. I developed this (for Version 0.9.5) before you
added Subtitles to JFreeChart. I had used the
terms title and subtitle as follows: a title takes a
complete line across the top or bottom of the chart,
while a subtitle only applies to one of the three parts of
a line.
2. The SubTitle_TestChart.png shows the
use/placement of these titles & subtitles. The text of
each line describes the following:
a. The order in which each line was added to the
chart: (Draw Order=n)
b. The type of TextTitle: Title or SubTitle
c. The requested placement of the string: POSITION_TL
(TC, TR, Top, BL, BC, BR, etc.)
d. The font size: Font=n
3. I did quick update for V 1.0.0-pre2 (just released).
You seem to have deleted the Legend and now have
a LegendTitle instead, so I had to add some code to
process any LegendTitle lines AFTER any BOTTOM
title/subtitles in order for it to come out in the proper
place on the chart (see JFreeChart.java, draw() - lines
968-978). I only allowed for one such LegendTitle line;
the code could be easily expanded to allow multiple
such lines.
4. I have marked all changes to the existing 1.0.0-pre2
code with //| in the right margin. See the
attached JFreeChart.java and TextTitle.java files.
Description:
I've made an addition to JFreeChart.java
and TextTitle.java to allow writing strings in one of three
areas (Left, Center, or Right) at the Top or Bottom of a
chart. (The attached .zip file has the code and sample
charts referenced below. Different Text Strings may be
added to each section of a line individually (with different
Fonts, sizes, colors, etc.).
Any title String drawn with the current implementation
takes the whole width of the. I am calling this type of
text a title (uses whole line). This capability still
remains, and is the default.
The modification allows the TextTitle class to flag an
instance as a subtitle. A subtitle can be placed at
the TOP or BOTTOM of the chart and in one of 3 relative
columns on the LEFT, in the CENTER, or to the RIGHT
(see the attached SubTitle_TestChart.png). The area
used by each column is managed separately: different
sizes of text can be used for different subtitles in any
location.
TOP lines are added from the top of the chart down;
BOTTOM lines are added from the bottom of the chart
upwards.
Note that title and subtitle lines can be inter-mixed.
All subtitles added after any title will be below that title
(or above it, for a BOTTOM placement). Any title added
after a subtitle will be on a line across the whole chart
below the largest of the 3 areas (or above, for a
BOTTOM placement). The (Draw order=8) Title-TOP
and (Draw order=9) Title-BOTTOM lines on
SubTitle_TestChart.png show this.
TextTitle: I added one constructor with a logical to allow
creating an instance as a subtitle the Boolean subtitle
variable (default=false), and accessor methods to
set/query the state of this variable. (If it would be
desirable to have this capability with other text classes,
e.g., allowing images, these additions should be moved
from TextTitle to AbstractTitle.)
JFreeChart: I added the variables and processing (in the
draw and drawTitle methods) to check any TextTitle
instance for the status of the subtitle variable and draw
as a subtitle if it is set. If it is not (default), the
current title processing is used.
Sample charts, JFreeChart & TextTitle code changes