3
Programming JClass Chart 3D: Surfaces and Bars
Fifteen Basic Types of Surfaces and Bars Chart Types Bar Charts and Histograms
Contours and Zone Display Mesh Controls Surface Colors Solid Surface
All elements mentioned in this chapter refer to both the Java 2 API
and the Java 3D API, unless specifically noted.
3.1 Fifteen Basic Types of Surfaces and Bars
One of the types of data that can be attached to JClass Chart 3D is grid data. Grid data that has been attached to the chart can be displayed in a surface, bar, or scatter plot representation. Grid data is supplied to the chart via
Chart3dDataView
'selevationDataSource
property. The chart then processes the data and stores it in an internal data object of typeChart3dGridData
. For elevation data, this internal object can be referenced via theelevationData
property. The user can retrieve this internal object, query it for data values, and set certain properties on it.The chart uses elevation data to draw a surface plot, bar plot, or scatter plot, depending on the
chartType
, which will beSURFACE
,BAR
, orSCATTER
.An
elevationDataSource
must implement theChart3dDataModel
interface. To be grid data, it must also implement theChart3dGridDataModel
interface. This promises the chart that it can supply anxGrid
array, ayGrid
array, and a doubly indexedzValues
array. If the datasource wants to provide X- and Y-data labels to the chart, it should implement theLabelledChart3dGridDataModel
interface. Similarly, a hole value, other than the default, can be provided through theHoleValueChart3dDataModel
. Data values can be edited through theEditableChart3dDataModel
and data changes can be monitored if the datasource implements theChart3dDataManager
interface.The
elevationDataSource
can also take points as its data type. This type of data can only be used for scatter plots.Note that using a data set of type
point
with a chart type ofSURFACE
orBAR
will produce a blank plot.When grid data is used and the chart type is either
SURFACE
orBAR
, JClass Chart 3D's four basic display Boolean properties -Meshed
,Shaded
,Contoured
, andZoned
- combine to create 15 different basic surface and bar displays. No graph is displayed when all four Booleans arefalse
.
3.1.1 JCElevation: Meshed, Shaded, and Transparent Plots
The
JCElevation
object determines whether surface and bar plots are Meshed, Shaded, or Transparent. TheJCElevation
constructor initializes theMeshed
,Shaded
, andTransparent
properties (each of which takes a Boolean value). The defaults for each of these areMeshed=true
,Shaded=false
, andTransparent=false
.Meshed
Surfaces: When
Meshed
istrue
, JClass Chart 3D displays the X-Y grid projected onto the 3D surface in a 3D view with a Z-axis. You can use thexMeshShow
andyMeshShow
properties ofJCSurface
to individually control whether the X- and Y-mesh lines are showing.The
xMeshFilter
andyMeshFilter
properties ofJCSurface
allow every nth mesh line to be drawn. By default, the chart chooses a pleasing filtering. ThemeshTopColor
andmeshBottomColor
properties allow the user to control the top and bottom colors of the mesh lines.Bars: When
Meshed
istrue
, JClass Chart 3D will draw the outline of all the bars. All bars with a value greater than or equal to the origin of the Z-axis will be outlined using themeshTopColor
, and all bars with a value less than the origin will be outlined using themeshBottomColor
. WhenTransparent
istrue
, all the lines of every bar will be visible.Shaded
Surfaces: When
Shaded
istrue
, JClass Chart 3D displays the data as a flat shaded surface in a 3D view with a Z-axis. The surface color is controlled with theshadedTopColor
and theshadedBottomColor
properties (not currently available in the Java 3D API version of JClass Chart 3D).Bars: When
Shaded
istrue
, JClass Chart 3D draws each bar as a solid bar. All bars with a value greater than or equal to the origin of Z-axis will be drawn using theshadedTopColor
, while all bars with a value less than the origin will be drawn using thesurfaceTopColor
.The following code snippet shows setting these properties:
JCElevation elevation=c.getDataView(0).getElevation();
elevation.setMeshed(true);
elevation.setShaded(true);
elevation.setTransparent(false);
3.1.2 JCContour: Contoured and Zoned Plots
The
JCContour
class deals with information about contours and zones. Two of its properties areContoured
andZoned
. Both default tofalse
.Contoured
Surfaces: When
Contoured
istrue
, JClass Chart 3D examines the distribution of the data, using theJCContourLevels
class, and draws contour lines demarcating each of the contour levels. The contour line style, thickness, and color are controlled with thecontourStyles
property.Bars: When
Contoured
istrue
, JClass Chart 3D examines the distribution of the data, using theJCContourLevels
class, and draws contour lines around the bars, demarcating each of the contour levels. The contour line style, thickness, and color are controlled with thecontourStyles
property.Zoned
Surfaces: When
Zoned
istrue
, JClass Chart 3D examines the distribution of the data, using theJCContourLevels
class, and fills each level with a solid color. (UnlessMeshed
istrue
andShaded
isfalse
, in which case the fill color is used to draw each level's mesh lines.) The color for each level is specified with thecontourStyles
property.Bars: When
Zoned
istrue
, JClass Chart 3D examines the distribution of the data, using theJCContourLevels
class, and fills each level within each bar with a solid color. (UnlessMeshed
istrue
andShaded
isfalse
, in which case the fill color is used to draw each level's mesh lines.) The color for each level is specified with thecontourStyles
property. IfzoneDataSource
is supplied to the data view, each bar is filled with a solid color. Otherwise, the bar is segmented by height according to the contour levels.
3.2 Chart Types
The following table shows the 15 basic graph types:
GraphChart Type
Meshed
Shaded
Contoured
Zoned
Surface Example
Bar Example
Comments
Displays surface and bars in a flat shade. Top and bottom colors may be set.
Contour lines are automatically drawn between distribution levels in the data.
Zoned1.
Similar to Contoured, except that each distribution level is displayed in a solid color.
Draws surface as a mesh and bars in outline. Surface and bars are flat shaded.
Displays surface as a mesh and bars in outline. Also draws contour lines along borders between distribution levels in the data.
Displays surface as a mesh and bars in outline. Uses zoning colors for mesh and bar outlines.
Displays a flat-shaded surface or bars with contour lines superimposed.
Displays contour lines and flat shaded zone colors to demarcate levels in the data.
Similar to Shaded, Zoned, but with a mesh or bar outlines superimposed.
Similar to Meshed, Shaded, but contour lines are superimposed.
Similar to Shaded, Zoned, but contour lines are superimposed.
1In this release, Zoned is the same as Zoned and Shaded for bar charts. Application developers are urged to use the Zoned and Shaded combination for this view, since the interpretation of the Zoned combination may change in a future release.
3.3 Bar Charts and Histograms
When
chartType
isBAR
, the elevation data will be displayed as a bar chart (if grid data is supplied). Each data point will be represented by a single bar. The spacing between adjacent elements in the grid is honored.Bar Z Origin
Bars start from the z Axis origin, which can be controlled through
JCAxis
' origin property. The default value of the origin is 0.0. WhenShaded
istrue
, bars that have values greater than the origin are rendered in theshadedTopColor
property of theJCElevation
class. Negative bars (that is, bars with values less than the origin) are rendered in theshadedBottomColor
.Bar Spacing
The amount of space occupied by a bar, as a percentage of the maximum amount possible, is controlled through the
xSpacing
andySpacing
properties of theJCBar
class. The default is 80%. Setting it smaller results in thinner bars. Setting bar spacing to 100% (the maximum) results in bars that about one another.
Figure 11 : Fixed Bar Chart with X-Spacing set to 1% and Y Spacing set to 100%.
Histograms
To display a histogram, set both the
xFormat
andyFormat
properties ofJCBar
toHISTOGRAM
(default isFIXED
). Thus, the X-axis and Y-axis can be independently switched between fixed and histogram formats.If the X-axis is switched to a histogram, each bar's left edge will be drawn aligned with corresponding X-values in the data. The width of each bar will be the distance between subsequent X-values in the data. Since the width of each bar is derived from the spacing between its neighbors, there is always one fewer bar along a histogram axis than there is if the same data is displayed along a fixed axis.
Histograms usually make good use of data whose grid values are not equally spaced. This gives control over spacing in the data grid.
Figure 12 : Fixed versus Histogram Display of Identical Data.
Grid Colors
If
Shaded
istrue
andZoned
isfalse
, the colors of the individual bars can be controlled. Normally, all bars with a value below the origin are colored withshadedBottomColor
, and all others are colored withshadedTopColor
. However, in some situations, it is useful to color a row, column, or individual bar in the chart with a distinct color.The
JCGridColor
class is used to specify the fill color of a group of bars, or of an individual bar. TheChart3dDataView
class'gridColors
property stores a list ofJCGridColor
objects.The
JCGridColor
class has adataIndex
property and acolor
property. ThedataIndex
is a reference to aJCData3dGridIndex
object which stores an index to a bar or group of bars. Thecolor
property indicates what color to make the bars referenced by thedataIndex
.An individual bar can be colored by specifying its indices in the
dataIndex
object. For example, to set the bar in the third X-data line, second point to red, set thexIndex
property of thedataIndex
to 2, theyIndex
to 1, and the color toColor.red
.To specify the color of an entire row of bars, set the other index to
JCData3dIndex.ALL
. For instance, the entire fifth X line of bars is set to green by setting thexIndex
property of thedataIndex
to 4, theyIndex
toJCData3dIndex.ALL,
and the color toColor.green
. To set the color of all the bars, set both thexIndex
andyIndex
of thedataIndex
toJCData3dIndex.ALL
.
Chart3dDataView
has several convenience methods for manipulating the list ofJCGridColors
. It hasaddGridColor()
andremoveGridColor()
for adding and removing grid colors. It also has afindGridColor()
method which retrieves the first grid color that matches a given (xIndex, yIndex) index starting from the end of the list; this is what the chart uses to determine the color of a given bar. IffindGridColor()
returns null, the bar color falls back to either theshadedTopColor
or theShadedBottomColor
.JClass Chart 3D's
Chart3dDataView
will only maintain one entry per (xIndex, yIndex) combination. Whenever a second entry for the same indices is supplied, the first entry is removed. Later entries take precedence over earlier entries.The following code created the bar coloring in Figure 13:
dataView.addGridColor(JCData3dIndex.ALL, JCData3dIndex.ALL, new Color(255, 208, 0));
dataView.addGridColor(1, JCData3dIndex.ALL, Color.blue);
dataView.addGridColor(JCData3dIndex.ALL, 1, new Color(176, 32, 240));
dataView.addGridColor(1, 1, Color.red);
Figure 13 : 3D Chart demonstrating numerous grid colors.
Note that even though the index of the bar at (1, 1) matches every entry in the list, the bar is colored red because it matches the last entry in the list.
3.4 Contours and Zone Display
When
Contoured
orZoned
istrue
, JClass Chart 3D marks each contour level from an array of 100 built-in contour styles.Each contour style contains information about the contour line style, width, pattern, color, and zone color (used to mark each level). Contour styles can be customized by an application. Please see Customizing Contour Styles, in Chapter 6 for details.
Contour Styles Used
JClass Chart 3D determines which contour style to use for a particular level automatically, evenly distributing the styles through the number of levels, as shown by Figure 14.
Figure 14 : A Sampling of Supplied Contour Styles Used as Needed.
By implementing the
JCContourMapping
interface and using thesetContour.Mapping()
method of theJCContour
class, you can override the default level to contour style mapping.Also, by using the
JCContourLevels
class, you can specify your own contour levels (such as an array of doubles). You can also use your own contour styles by setting thecontourStyles
property of theJCContour
class. For further information, please see Advanced JClass Chart 3D Programming, in Chapter 6.Contour/Zone Projection
The
JCProjection
class specifies information about the Contoured and Zoned projections on the top and bottom of the plot cube. For instance, you can use thesetContoured
method to set the projection to be Contoured, and you can use thesetZoned
method to set the projection to be Zoned.The
JCPlotCube
floor property is aJCProjection
that indicates whether a projection should be drawn on the bottom of the plot cube. If either theContoured
orZoned
property of the floor projection istrue
, a projection is drawn. Similarly, the ceiling projection controls what type of projection is drawn on the top of the plot cube.These properties do not depend on the values of
Contoured
andZoned
of theJCContour
class. However, any other property that affects contour generation or rendering affects projected contours/zones. Floor and ceiling projections are ignored in 2D graphs, bar charts, and scatter plots.
Figure 15 : Projecting Contours and Zones.
Zone Method
An application can control the method used to fill each zone region by leveraging the
ZoneMethod
property of theJCContour
class. By default, JClass Chart 3D fills between each contour interval (ZONE_CONTOURS
). When set toZONE_CELLS
_AVERAGE
, JClass Chart 3D fills entire cells in the grid based on the average of the four corners of the cell. Figure 16 illustrates the difference visually. When set toZONE_CELLS_CORNER
, entire cells are filled using the value at the bottom left corner of the cell.Cell zoning produces a coarser-looking surface, but offers significant performance advantages over contour zoning. However, the visual difference between the two types of zoning diminishes with larger grids.
Figure 16 : Contour Zoning (left) and Cell Average Zoning (right).
3.5 Mesh Controls
Mesh Colors
Mesh colors are controlled by methods in the
JCElevation
class.The bottom and top colors of the mesh drawn when
Meshed
istrue
can be set withsetMeshTopColor
andsetMeshBottomColor
. They are both "black" by default. See Chart Colors, in Chapter 1 for details on setting colors.Mesh Filtering
Methods in the
JCSurface
class control mesh filtering. This class contains properties that pertain to surface plots.The
xMeshFilter
andyMeshFilter
properties specify how the mesh is filtered before being displayed. By default, no filtering is performed. When set to 0, JClass Chart 3D automatically filters the mesh to provide a pleasing display, and changes the filter as the graph is scaled or the data changes.You can hard-code a mesh filter by setting these properties to any positive integer. For example, a value of 5 filters the mesh so that every 5th line is drawn.
Figure 17 : Effect of Mesh Filtering.
Hidden Mesh Lines
When
Meshed
istrue
andShaded
isfalse
, grid and contour lines that are obscured from view by intervening portions of the scene are not displayed by default. To display these lines, set theTransparent
property ofJCElevation
is totrue
.
Figure 18 : Hidden line removal.
3.6 Surface Colors
The bottom and top colors of the shaded surface drawn when Shaded is true can be set with
shadedTopColor
andshadedBottomColor
of theJCElevation
class. By default the bottom color is "dim grey" or RGB(112,112,112) and the top color is "light grey" or RGB(211,211,211). See Chart Colors, in Chapter 1 for details on setting colors. Please note thatshadedTopColor
andshadedBottomColor
are currently not available for surfaces in the Java 3D API version of JClass Chart 3D.
3.7 Solid Surface
Setting the
Solid
property ofJCSurface
totrue
will cause JClass Chart 3D to draw a skirt around the data, thereby joining the edge of the surface to a plane at the minimum Z value, as shown in Figure 19.
Figure 19 : Setting Solid Surface On and Off.