To improve a chart's readability, Chart FX for Java supports the creation of
titles that you can use to create a chart's main title. A title is a string
that can be assigned to any portion outside the main chart area.
This string can be positioned, aligned and formatted according
to the different properties supported by TitleDockable object that supports an unlimited number of titles in the chart area. Titles can be assigned via the Chart FX for Java designer properties list or you can create and control them
programmatically.
By default, all the titles you create will be positioned at top of the chart, or
where the main chart title is displayed. For example, if you add the following
code to an event handler (button) it will create a title on the top portion of
the chart.
chart1.getTitle(0).setText("My Chart Title");
|
You can create multi-line titles by simply adding an additional title in the
same position. These lines can then be independently aligned and formatted.
The Title object supports a series of properties that you can use to
align, position and format the different titles in the chart. For example, the
following code adds a main title and labels the chart's Y-axis.
Title title1 = chart1.getTitle(0); title1.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD,16)); title1.setText("My Chart Title"); title1.setTextColor(java.awt.Color.white); title1.setBackColor(java.awt.Color.blue); title1.setDrawingArea(false); TitleDockable title2 = chart1.getTitle(1); title2.setDockArea(DockArea.LEFT); title2.setLineAlignment(StringAlignment.FAR); title1.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD,10)); title2.setText("Sales in Dollars"); title2.setTextColor(java.awt.Color.black);
|
TitleDockable Class
The TitleDockable class supports the DockArea property and LineAlignment
property that allow a title to be docked in the chart area. In order to
utilize this functionality, you must create your title objects as a
TitleDockable object. In the previous sample, title2 was created using the
TitleDockable class.
|