JClass Chart 3D

PreviousNextIndex

2

Programming JClass Chart 3D: Common Functions

Properties  Axis Controls   Setting Axis Bounds   Legends   Perspective 

Axis Scaling  Axis Labelling and Annotation Methods   Gridlines  Header and Footer Titles

Adding Header, Footer, and Labels

All elements mentioned in this chapter refer to both the Java 2 API
and the Java 3D API unless specifically noted.



2.1 Properties

"Properties" are the named method attributes of a class that can affect its appearance or behavior. Properties that are readable have a "get" (or "is" for Booleans) method, which enables the developer to read a property's value, and those properties that are writable have a "set" method, which enables a property's value to be changed.

For example, the JClass Chart 3D JCAxis class has a property called annotationMethod, which is used to indicate the style of annotation used on the axis. To set the property value, the setAnnotationMethod() method is used. To get the property value, the getAnnotationMethod() method is used.

It is not necessary to remember all the properties in order to program JClass Chart 3D effectively. For most charts, many properties may be left with their default settings. A full summary of the JClass Chart 3D properties for all commonly used classes is provided in Appendix B. Scan through those tables to gather a basic understanding of the properties. Not all the properties are used for all types of charts: some are specific for Surface and Bar charts only, while others are for Scatter Plots only.

For complete details on how JClass Chart 3D's object properties are organized, see JClass Chart 3D Object Containment and Setting and Getting Object Properties, in Chapter 1.

2.1.1 Setting JavaBean Properties at Design-Time

JClass Chart 3D has two JavaBeans: chart3dJava2d for Java 2 and chart3dJava3d for the Java 3D API.

One of the features of any JavaBean component is that it can be manipulated interactively in a visual design tool (such as a Java IDE) to set the initial property values when the application starts. Consult your IDE's documentation for details on how to load third-party JavaBean components into the IDE.

For details on JClass Chart 3D's JavaBeans and IDEs, please refer to the JClass and Your IDE chapter in the JClass DesktopViews Installation Guide. The JClass DesktopViews Installation Guide is available in HTML and PDF formats, and is included when you purchase JClass Chart 3D. The readme file contains the most current list of supported IDEs.

Most IDEs list a component's properties in a property sheet or dialog. Simply find the property you want to set in this list and edit its value. Again, consult the IDE's documentation for complete details.

2.1.2 Setting Properties Interactively at Run-Time

If enabled by the developer, end-users can manipulate property values on a chart running in your application. Clicking a mouse button launches the JClass Chart 3D Customizer. The user can navigate through the tabbed dialogs and edit the properties displayed.

For details on enabling and using the Customizer, please see The JClass Chart 3D Customizer, in Chapter 1, as well as Programming User Interaction, in Chapter 7.


2.2 Axis Controls

2.2.1 Axis Show

The show property of JCAxis tells JClass Chart 3D whether it should draw the axis at all. If set to false, the axis will not be drawn.

2.2.2 Axis Font and Size

The axis annotation is rendered using the font specified by the annoFont property of JCAxis. The font is scaled to be the size specified by the annoFontCubeSize property.

The annoFontCubeSize is measured in units, which are each 1/1,000 of the plot cube length. The default annoFontCubeSize is 80, which means the characters are 8% of the length of the plot cube high. Thus, if the plot cube changes size, so does the annotation.

2.2.3 Title

The JCAxis title property may be used to specify a title for each axis. Titles are rendered using titleFont and in a size specified by titleFontCubeSize.


2.3 Setting Axis Bounds

Normally a graph displays all of the data it contains. There are situations where only part of the data is to be displayed. This can be accomplished by fixing axis bounds.

2.3.1 Min and Max

Use the min and max properties of JCAxis to frame a chart at specific axis values. The minIsDefault and maxIsDefault properties allow the chart to determine axis bounds automatically, based on the data bounds.

If the minIsDefault property of a JCAxis object is true, every time the JClass Chart 3D data is changed, JClass Chart 3D will determine a reasonable default value for the axis minimum. If false, JClass Chart 3D will use the provided axis minimum.

Please note that there is a restriction on the min and max properties of the Z-axis; these are not allowed inside the Z-range of the data.

A side effect of setting any property that has a corresponding UseDefault property is that the UseDefault property will be set to false.

The following code will freeze the value of minIsDefault at its current value. It will also have the side effect of setting minIsDefault to false.

  JCAxis yAxis = c.getChart3dArea().getYAxis();
  yAxis.setMin(yAxis.getMin());

The following code will revert back to the default behavior, enabling JClass Chart 3D to calculate a default value for minIsDefault whenever it draws the graph.

  yAxis.setMinIsDefault(true);

2.4 Legends

A legend itemizes the visual attributes used to identify data in the chart. You can customize the labels in the legend and the position of the legend. The legend is a JComponent, and all properties apply.

The getLegend() method of JCChart3d returns an instance of the abstract class JCLegend so that any subclass may be used as a legend. To utilize some of the 3D-specific properties described below, such as layoutStyle and distributionRange, you will need to cast the class to JCChart3dLegend. For example:

JCChart3dLegend legend = (JCChart3dLegend) chart3d.getLegend();

2.4.1 Legend Display

JClass Chart 3D will generate a legend only when the legend's Visible property is set to true. By default, there is no legend displayed.

If contours are drawn and zones are not, a legend listing the contour lines is generated. If zones are drawn, the legend lists the fill colors for each level. If points are drawn, the legend lists the symbols used for each series of points.

By default, JClass Chart 3D will attempt to list the legend contents vertically and position the legend to the right (that is, east) of the graph area.

2.4.2 Legend Text, Orientation, and Positioning

Legend Text

How the legend displays the text depends on the type of chart and data being plotted. In most cases, the text is based on contour levels.

If a scatter chart is plotting point data, the text is based on the label property of each series in the data view. If a scatter chart is plotting grid data with both zones and contours turned off, the text is based on the name property of the grid data object.

Legend Orientation

Use the legend Orientation property to lay out the legend horizontally or vertically.

Legend Positioning

The JCChart3dLegend class positions items in a grid wherein every row has the same height and every column the same width. JCChart3dLegend is a subclass of the abstract class JCLegend, and all of JCLegend's properties are inherited by JCChart3dLegend.

Use the legend Anchor property to specify where to position the legend relative to the chart3dArea. You can select from eight compass points around the chart3dArea.

Figure 6 :  Vertically oriented legend anchored NorthEast.

2.4.3 Scatter Plot Charts

Scatter Plots of Point Data

For scatter plots of point data, the legend labels are derived from each Chart3dPointSeries label property (found in the Chart3dPointData object). Each label's corresponding symbol is determined from the SymbolStyle located in the series' ChartStyle property.

Scatter Plots of Grid Data

For scatter plots of grid data, the legend style depends on whether the contouring information has been computed (that is, if either of the contoured and zoned properties of the dataView's contour object are true, the contours are computed). If contouring information has been computed, the legend entries are the same as they would be for surface plots and bar charts (see Section 2.4.4, Surface and Bar Charts). For each contour level there is also a symbol that is plotted (retrieved from the SymbolStyle property of the contour style for this level).

If the contours are not computed, the LineStyle and SymbolStyle from the Chart3dGridData object's ChartStyle property are used to draw a single legend entry. The label for this entry is derived from the Name property of the Chart3dGridData object.

2.4.4 Surface and Bar Charts

For surface and bar charts, the legend labels are determined by the value of the contours being used by the chart, while the color swatch is determined by each contour's contourStyle object. There are also variations, depending on selected properties (detailed below) of the chart and legend.

When applicable, the LayoutStyle property of the legend determines the type of layout that the legend will use. Please see later in this section for more information.

Possible values for the LayoutStyle property are CONTINUOUS and STEPPED. CONTINUOUS is the default and displays the contour style fill colors as a continuous range, with contour level values placed at the transition points. STEPPED breaks down this continuous range into a series of smaller ranges defined by each contour level color.

Figure 7 :  Continuous (left) and Stepped (right) Legends.

For example, an item in a STEPPED legend will show a box of color followed by a String of the form "min .. max". The min and max values are determined by the values of the contour levels that bound this range. The color is determined by the fill color of the contour style of the top contour level in the range. In most cases, the existing contour ranges will be extended to the min and max of the data.

This LayoutStyle property is ignored when other properties interfere with the way things can be laid out. For example, if zones are not being drawn (isZoned()=false on the JCContour or JCProjection objects), the legend will be drawn as a series of items, each representing one contour line. The color of the line in the legend is derived from the LineStyle of the JCContourStyle of the contour being referenced.

If shading is not being done (isShaded()=false on the JCElevation object), then the items in the legend will appear as a series of lines, each representing a different contour zone. The color is determined from the FillStyle of the JCContourStyle of the contour zone.

The DistributionRange property determines the range of contour levels to be displayed in the legend. If using the default contours, the DistributionRange property has no effect. If the user has specified contour levels, a value of RANGE_DATA (the default) will restrict the contour levels in the legend to those in the range specified by the data min and max. A value of RANGE_ALL will cause all user-set contour levels to display.

There is also a modest number of small properties of JCChart3dLegend that the user can set to change the layout of legend items:

2.4.5 Overriding Labels

There are two ways a user may override the default labels generated for the legend:

In the first method, the Labels property takes a List object that contains a List object for each data view. (Currently, JClass Chart 3D supports only one data view.) Each internal List contains a series of String or JCMultiFieldString objects that are to be used to override the default legend labels.

The labels are to be placed in sequence, from bottom to top legend item. For example, the first label in the List will be used to represent the bottom item in the legend. If the user does not give enough labels to cover those needed, JCChart3dLegend will use default labels for the remainder of the unspecified labels.

In the second method, the LabelGenerator property takes any class that has implemented the JCChart3dLegendLabelGenerator interface. This interface has one method:

Object generateLegendLabel(JCChart3d chart3d, int level, double zmin, double zmax, Object label)

where chart3d is the JCChart3d instance to which this legend is attached, level is the contour level this label represents, zmin is the minimum value of the contour level range, zmax is the maximum value of the contour level range, and label is the value of the legend item's label so far (that is, either the default generated label or the label specified by the user with the Labels property). Please note that in some cases, zmin and zmax will be equal.

Any String or JCMultiFieldString returned by the implementor of this method will be used to label the legend item for the specified contour level. If null is returned, no legend item will be created for the specified contour level.

2.4.6 JCMultiFieldString

The JCMultiFieldString class handles multifield Strings, where each field may have a different alignment of text within its field. This class is used by the JCChart3dLegend class to manage specialized legend text.

JCMultiFieldString encapsulates a String that has multiple String fields, each with a potentially different alignment. Here is an example of how it is created:

new JCMultiFieldString("\\rRight Text\\cCenter Text\\lLeft Text");

where \r represents right alignment of the field, \c represents center alignment of the field, and \l represents left alignment of the field. Each alignment character marks the beginning of a new field.

The JCMultiFieldString class converts this encoded String into an internal representation that can be drawn by JCChart3dLegend such that all fields are aligned as indicated. Any number of fields may be present.

This object may be included in either the Labels property or the Object that is returned by the method implementing the JCChart3dLegendLabelGenerator interface.

2.4.7 JCLegend Toolkit

The JCLegend Toolkit allows you the freedom to design your own legend implementations. The options range from simple changes, such as affecting the order of the items in the legend, to providing more complex layouts.

The JCLegend Toolkit consists of a JCLegend class that can be subclassed to provide legend layout rules and two interfaces: JCLegendPopulator and JCLegendRenderer. JCLegendPopulator is implemented by classes wishing to populate a legend with data, and JCLegendRenderer is implemented by a class that wishes to help render the legend's elements according to the user's instructions.

JCChart3dLegendManager is the class used by JClass Chart 3D to implement both the JCLegendPopulator and JCLegendRenderer interfaces, and to provide a built-in mechanism for itemizing range objects in a legend.

Custom Legends - Layout

To provide a custom layout, override the method:

public abstract Dimension layoutLegend(List itemList, boolean, vertical, Font useFont)

The itemlist argument is a List containing a Vector for each data view contained in the chart. Each of these sub-vectors contains one JCLegendItem instance for each series in the data view and one instance for the data view title.

The vertical argument is true if the orientation of the legend is vertical, and false if the orientation of the legend is horizontal.

The useFont argument contains the default font to use for the legend.

Each item in the legend consists of a text portion and a symbol portion. For example, in a JCChart3d STEPPED legend, the text portion is the range between two contour levels, while the symbol portion is the box of color used to represent such values on the chart. For the title of the data view, the text portion is the name of the data view, and there is no symbol.

JCLegendItem is a class that encapsulates an item in the legend with the properties.

Property name

Description

Point pos;

Position of this legend item within the legend.

Point symbolPos;

Position of the symbol within the legend item.

Point textPos;

Position of the text portion within the legend item.

Dimension dim;

Full size of the legend item.

Dimension symbolDim;

Size of the symbol; provided by legend populator.

Dimension textDim;

Size of the text portion; provided by legend populator.

Rectangle pickRectangle;

The rectangle to use for pick operations; optional.

int drawType;

Determines drawing type; one of JCLegend.NONE, JCLegend.BOX, JCLegend.IMAGE, JCLegend.IMAGE_OUTLINED, JCLegend.CUSTOM_SYMBOL,JCLegend.BOX_PLAIN, JCLegend.LINE, or JCLegend.CUSTOM_ALL.

Object itemInfo;

Data related to this legend item; in JCChart3d, this is an instance of the LegendEntry class, which contains information on the data represented by the legend item and the style objects used to draw it.

Object symbol;

The symbol if other than the default type; usually null (means drawLegendItem decides).

Object contents;

The text portion; in JCChart3d, this is either a String or a JCMultiFieldString.

When the itemList is passed to layoutLegend, it has been filled in with JCLegendItem instances representing each data series and data view title. These instances will have the symbolDim, textDim, symbol, contents, itemInfo, and drawType already filled in.

The value of drawType will determine whether a particular default symbol type will be drawn, or whether user-provided drawing methods will be called.

The layoutLegend() method is expected to calculate and fill in the pos, symbolPos, textPos, and dim fields. Additionally, the method must return a Dimension object containing the overall size of the legend. Optionally, it may also calculate the pickRectangle member of the JCLegendItem class. The pickRectangle is used in pick operations to specify the region in the legend that is associated with the data that this legend item represents. If left null, a default pickRectangle will be calculated using the dim and pos members.

Any of the public methods in the JCLegend class may be overridden by a user requiring custom behavior. One such method is:

public int getSymbolSize()

getSymbolSize() returns the size of the legend-calculated symbols to be drawn in the legend. Default JCLegend behavior sets the symbol size to be equal to the ascent of the default font that is used to draw the legend text. It is overridable by users who wish to use a different symbol size. One possible implementation is to use a symbol size identical to that which appears on the actual chart.

The easiest way to change default legend behavior without implementing all of the above is to subclass the existing JCChart3dLegend class. It implements all the above methods to lay out legend items in a straightforward grid.

Custom Legends - Population

JCLegendPopulator is an interface that can be implemented by any user desiring to populate the legend with custom items. This interface comprises two methods that need to be implemented:

public List getLegendItems(FontMetrics fm)
public boolean isTitleItem(JCLegendItem item)

getLegendItems() should return a List object containing any number of Vector objects where each Vector object represents one column in the legend. Each Vector object contains the JCLegendItem objects for that column. In JClass Chart 3D, each column generally represents one data view.

isTitleItem() should return true or false depending on whether the passed JCLegendItem object represents a title for the column. This is used to determine whether a symbol is drawn for a particular legend item.

If implemented, the legend should be notified of the new populator with the setLegendPopulator() method of JCLegend.

Custom Legends - Rendering

JCLegendRenderer is an interface that can be implemented by any user desiring to custom render legend items. This interface consists of five methods that need to be implemented:

public void drawLegendItem(Graphics gc, Font useFont, JCLegendItem thisItem)
public void drawLegendItemSymbol(Graphics gc, Font useFont, JCLegendItem thisItem)
public Color getOutlineColor(JCLegendItem thisItem)
public void setFillGraphics(Graphics gc, JCLegendItem thisItem)
public void drawLegendItemText (Graphics gc, Font useFont, JCLegendItem this Item);

drawLegendItem() provides a way for a user to define a custom drawing routine for an entire legend item. It is called when a legend item's draw type has been set to JCLegend.CUSTOM_ALL.

drawLegendItemSymbol() provides a way for a user to define a custom drawing routine for a legend item's symbol. It is called when a legend item's draw type has been set to JCLegend.CUSTOM_SYMBOL.

getOutlineColor() should return the outline color to be used to draw the legend item's symbol. If null is returned, the legend's foreground color will be used. getOutlineColor() is called when a legend item's draw type has been set to either JCLegend.BOX or JCLegend.IMAGE_OUTLINED.

setFillGraphics() should set the appropriate fill properties on the provided Graphics object for drawing the provided legend item. setFillGraphics() is called when the legend item's draw type has been set to JCLegend.BOX, JCLegend.BOX_PLAIN, or JCLegend.LINE.

drawLegendItemText() provides a way for the user to define drawing for custom text objects. When the legend does not recognize the object in the contents field of a JCLegendItem (that is, it is not a String), this method will be called.

If implemented, the legend should be notified of the new renderer with the setLegendRenderer() method of JCChart3dLegend.


2.5 Perspective

The JCView3d class' Perspective property controls the perspective effect observed by projecting the plot cube onto the screen (the default value is 2.5). Small values exaggerate the perspective effect, while large values diminish it. Valid values are between 1 and JCView3d.MAX_PERSPECTIVE which is 500.

Figure 8 :  Perspective Depth Measurement.


2.6 Axis Scaling

The JCPlotCube class can be used to adjust the X, Y and Z dimensions of the unit cube relative to one another for Surface, Bar, or Scatter Plot charts. For example, if you would like the 3D display to be twice as long in the Y direction as in the X, set the Y scale to twice the X-scale. The default value of each Scale property is 1.0.

Here is a code snippet showing how to produce the right most chart of Figure 9:

JCPlotCube plotcube=c.getChart3dArea().getPlotCube();
plotcube.setXScale(2.0);

plotcube.setZScale(0.5);

Setting the Z scale higher or lower has the effect of flattening or stretching the surface view.


.
Figure 9 :  Axis scaling using various X: Y: Z ratios.


2.7 Axis Labelling and Annotation Methods

There are several ways to annotate the chart's axes, each suited to specific situations. The chart can automatically generate numeric annotation appropriate to the data it is displaying; you can provide a label for each grid point in the chart (X- and Y-axis for grid data only); you can provide a label for specific values along the axis.

Whichever annotation method you choose, the chart makes considerable effort to produce the most natural annotation possible, even as the data changes. You can fine-tune this process using axis annotation properties.

2.7.1 Choosing Annotation Method

A variety of properties combine to determine the annotation that appears on the axes. The JCAxis AnnotationMethod property specifies the method used to annotate the axis. The valid annotation methods are:

JCAxis.ANNOTATION_VALUES

(default)

The chart chooses appropriate axis annotation automatically (with possible callbacks to a label generator), based on the data.

JCAxis.ANNOTATION_DATA_LABELS

 

The chart spaces the points based on the X-and Y-grid values and annotates them with text you specify (in the grid data source) for each point.

JCAxis.ANNOTATION_VALUE_LABELS

The chart annotates the axis with text you define for specific X-, Y-, or Z-axis coordinates.

The following topics discuss setting up and fine-tuning each type of annotation.

2.7.2 Values Method

When the annotationMethod property is set to ANNOTATION_VALUES, JClass Chart 3D will automatically annotate the axis based on the range of data. This is the default annotation method. It is most suitable for the Z-axis, and for the X- and Y-axes when the chart type is surface.

2.7.3 Data Labels Method

If grid data is being plotted, individual lines in a surface, or a row/column of bars, can be labelled using the ANNOTATION_DATA_LABELS method.

This annotation method uses an array of Strings supplied as xLabels or yLabels through the LabelledChart3dGridDataModel interface to annotate each line from the grid. If a String in the list is null, a label is not drawn for that grid value, but the corresponding tick is drawn. The xLabels and yLabels array can also be set directly through methods provided in the Chart3dGridData class. Labels can be set as a list of Strings or as an ArrayList of objects of type String, JCValueLabel, or any other object whose toString() value is meant to be used as the label.

Data Label Clustering

Consecutive data labels can be combined into one label (in other words, when data labels are aggregated into a label cluster where only one label is displayed). In order for this to happen, ensure that:

If data labels are specified via a list of String objects, and m consecutive labels are identical (they must point to the exact same String), they form a cluster of m labels, from which one is used to draw the label. If m is odd, the middle label of the cluster is used as the label. If m is even, a new label is positioned at the average value of the labels. The tick marks and gridlines in the cluster range are still drawn as if there was no clustering.

If data labels are specified via a list of JCValueLabel objects, the label property of the valueLabels in the same cluster must point to the same String object. In the same way that data labels are handled with a list of String objects, if consecutive valueLabels do not contain to the same label object, they will not belong to the same cluster (even if the equals method would return true). This allows the user to have two consecutive identical Strings without forcing them to be in the same cluster.

2.7.4 ValueLabels Annotation

ValueLabels annotation displays labels at the axis coordinate specified. This is useful for displaying special text at a specific axis coordinate, or when a type of annotation that the chart does not support is needed, such as scientific notation. You can set the axis coordinate and the text to display for each ValueLabel, and also add and remove individual ValueLabels.

Figure 10 :  Using ValueLabels to annotate axes.

Every label displayed on the axis is one ValueLabel. Each ValueLabel has a Value property and a Label property. Additionally, the tickDrawn, labelDrawn, and minorTick properties control the display of the label and tick of the value label. The background and foreground of each label can also be set. These are null by default (in other words, no background is drawn, and the foreground color of the plot cube is used).

Please note that background colors for labels is currently not available in the Java 3D API version of JClass Chart 3D.

If the AnnotationMethod property is set to JCAxis.ANNOTATION_VALUE_LABELS, the chart places labels at explicit locations along an axis. The ValueLabels property of JCAxis, which is a collection of ValueLabels, supplies this list of Strings and their locations. For example, the following code sets value labels at the locations 10, 20 and 30:

JCAxis x=c.getChart3dArea().getXAxis();
x.setValueLabels(0, new JCValueLabel(10, "Label"));
x.setValueLabels(1, new JCValueLabel(20, "Label 2"));
x.setValueLabels(2, new JCValueLabel(30, "Label 3"));

The ValueLabels collection can be indexed either by subscript or by value:

JCValueLabel v1
// this retrieves the label for the second Value-label
v1=c.getChart3dArea().getXAxis().
getValueLabels(1);
// this retrieves the label at chart coordinate 2.0
v1=c.getChart3dArea().getXAxis().
getValueLabels(2.0);

2.7.5 Custom Axes Labels

JClass Chart 3D will label axes by default. However, you can also generate custom labels for the axes by implementing the JCLabelGenerator interface. This interface has one method - makeLabel() - that is called when a label is required at a particular value.

To generate custom axes labels, the axis' AnnotationMethod property, which determines how the axis is labelled, must be set to ANNOTATION_VALUES. Also, the axis' setLabelGenerator() method must be called with the class that implements the JCLabelGenerator interface.

The makeLabel() method is called for each label and tick that gets generated along the axis.

The makeLabel() method takes one parameter: vLabel (the internal value label that will be used to annotate the value). The user can then modify the label and the other properties of the value label.

Here is a code example showing how to customize the labels for a linear axis by implementing the JCLabelGenerator interface. In this case, Roman numeral labels are going to be generated (instead of the usual Arabic labels) for the numbers 1 through 10.

class MyLabelGenerator implements JCLabelGenerator
{
public void makeLabel(JCValueLabel vLabel) {
int intvalue = (int) vLabel.getValue();
String s = null;
switch (intvalue) {
case 1 :
s = "I";
break;
case 2 :
s = "II";
break;
case 3 :
s = "III";
break;
case 4 :
s = "IV";
break;
case 5 :
s = "V";
break;
case 6 :
s = "VI";
break;
case 7 :
s = "VII";
break;
case 8 :
s = "VIII";
break;
case 9 :
s = "IX";
break;
case 10 :
s = "X";
break;
default :
s = "";
         vLabel.setTickOnly(true);
return;
}
vLabel.setLabel(s);
     vLabel.setTickOnly(false);
}
}

Note that you will need to specify the label generator as follows:

axis.setLabelGenerator(new MyLabelGenerator());

Also note that JClass Chart 3D calls the makeLabel() method for each needed label and tick. Thus, if JClass Chart 3D needs n labels and ticks, the makeLabel() method is called n times.

2.7.6 Rotating Axis Labels

The annotationRotation property allows you to specify the rotation of a chart's axis labels. The default value is ANNOTATION_ROTATION_DEFAULT. When explicitly setting the annotation rotation for an axis, please note that the number of labels may not change from the default case, even if more will fit on the axis.

Note: If the axis annotation rotation is explicitly set to horizontal or vertical, there may be overlapping labels.

JCAxis.ANNOTATION_ROTATION_HORIZONTAL

The given axis annotation will be horizontal (parallel to the axis).

JCAxis.ANNOTATION_ROTATION_VERTICAL

The given axis annotation will be vertical (orthogonal to the axis).

JCAxis.ANNOTATION_ROTATION_DEFAULT

JClass Chart 3D determines the axis annotation orientation.

If the chart is a projection, the annotation orientation for the X-axis is horizontal and the annotation orientation for the Y-axis is vertical.

If the chart is not a projection, the annotation method plays a roll in determining the annotation orientation. If the annotation method is Values, the axis annotation will be horizontal. If the annotation method is ValueLabels or DataLabels, the orientation is horizontal when the maximum label length is 1; otherwise, the orientation is vertical.

2.7.7 Label Selection and Clustering

Users can select labels through the normal "pick" mechanism of JClass Chart 3D. If the user instantiates a pick listener (this is part of the standard user actions; please see Mapping and Picking, in Chapter 7), the chart will return a JCData3dLabelIndex object if a label has been selected. The JCData3dLabelIndex has labelIndex and valueLabel properties which respectively store the selected label's index and the internal value label corresponding to the selected label. Note that in the event of label clustering the labelIndex will be the index of the first label in the cluster.

Please note that this is currently not available in the Java 3D API version of JClass Chart 3D.


2.8 Gridlines

Gridlines can be displayed on each of the three primary planes - the XY plane, the XZ plane, and the YZ plane - using the properties of the JCGridLines class. This class specifies which gridlines are drawn for a given axis, via a plane mask. Planes are selected by "or"ing in the appropriate plane constants.

These constants of the JCGridLines class specify the possible planes:

Constant

Value

Description

XY_PLANE

1

The XY plane.

XZ_PLANE

2

The XZ plane.

YZ_PLANE

4

The YZ plane.

For instance, the X-axis controls gridlines that are perpendicular to the X-axis in the XY and the XZ plane.

To draw X-gridlines in all applicable planes, set JCGridLines to the value (XY_PLANE | XZ_PLANE). To remove gridlines completely, set the value to 0.

As another example, here is a code sample showing how to set a plane mask:

JCGridLines gl=c.getChart3dArea().getZAxis().getGridLines();
gl.setPlaneMask(XZ_PLANE|YZ_PLANE);

Gridlines are drawn where annotation is drawn on the axis, regardless of the annotation method.

2.8.1 Gridline Styles

The gridline's style - color, pattern, and width - are controlled by the JCLineStyle class. A JCGridLines object initializes its lineStyle so that by default, a solid black line of width 1 is drawn. The properties of the initial default lineStyle can be changed or a new lineStyle can be set on the JCGridLines object.

Here's an example showing the code to set the Y-axis gridlines to blue, have a dash_dot pattern, and be 4 pixels in width:

JCGridLines g1=c.getChart3dArea().getYAxis().getGridLines();
g1.setLineStyle(new JCLineStyle(4,Color.blue,JCLineStyle.DASH_DOT));

Color

To set the color of the gridlines, choose the AWT color class representing the color to be used to draw the lines. If null, the current color of the Graphics object is used. The following table summarizes the built-in color names defined in java.awt.Color:

Built-in Colors in java.awt.Color

black

blue

cyan

darkGray

gray

green

lightGray

magenta

orange

pink

red

white

 

yellow

 

Alternately, you can specify a color by its RGB components, useful for matching another RGB color. RGB color specifications are composed of a value from 0 - 255 for each of the red, green and blue components of a color. For example, the RGB specification of Cyan is "0-255-255" (combining the maximum value for both green and blue with no red).

Take care not to choose a gridline color that is also used to display data in the chart. The default JCLineStyle use all of the built-in colors in the following order: Red, Orange, Blue, Light Gray, Magenta, Yellow, Gray, Green, Dark Gray, Cyan, Black, Pink, and White. Note that JClass Chart 3D will skip colors that match background colors. For example, if the chart area background is Red, then the line, fill, and symbol colors will start at Orange.

Pattern

To set the pattern, use the Pattern property, which dictates the pattern used to draw a line. Choices for gridline pattern are:

You can also create a custom user-defined pattern for the gridlines. Here is a method declaration showing how to do this:

  public void setPattern(float[] patternArray, float[]
    legendPatternArray)

where patternArray is an array of floats representing the pattern to use when drawing this line, and legendPatternArray is an array of floats representing the pattern to use when drawing this line in the legend. A note of caution: if the values get too small, nothing will be drawn.

Width

The width of the gridlines can be set using the setWidth() method. A positive integer is required.


2.9 Header and Footer Titles

JClass Chart 3D can have two titles, called the header and footer. By default they are JLabel instances and behave accordingly (a JLabel class is a Swing class). A JLabel object can display text, an image, or both.

You can specify where in the label's display area the label's contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are left-aligned, by default. Image-only labels are horizontally centered by default.

A title consists of one or more lines of text with an optional border, both of which you can customize. You can also set the text alignment, positioning, colors, and font used for the header or footer.

See "How to Use Labels" in the Java Tutorial (http://java.sun.com/docs/books/tutorial/uiswing/components/label.html) for further information.


2.10 Adding Header, Footer, and Labels

JClass Chart 3D will always try to produce a reasonable chart display, even if very few properties have been specified. JClass Chart 3D will use intelligent defaults for all unspecified properties.

All properties for a particular chart may be specified when the chart is created. Properties may also be changed as the program runs by calling the property's set() method. A programmer can also ask for the current value of any property by using the property's get() method.

Adding Headers and Footers

To display a header or footer, the properties of the Header and Footer objects contained in the chart need to be set. For example, the following code sets the Text and Visible properties for the footer:

// Make footer visible
chart3d.getFooter().setVisible(true);
// By default, footer is a JLabel - set its Text property
((JLabel)chart3d.getFooter()).setText("1963 Quarterly Results");

The Visible property controls whether the header or footer is displayed. Text specifies the text displayed in the header or footer.

By default, the header and footer are instances of JLabel.


PreviousNextIndex