4
Programming JClass Chart 3D:
Scatter PlotsOverview Three Basic Types of Scatter Plots
Controlling Symbol and Drop Line Style Chart Styles
All elements mentioned in this chapter refer to both the Java 2 API and the
Java 3D API, unless specifically noted.
4.1 Overview
As noted in the previous chapter, if grid data is provided to the chart via the
elevationDataSource
property of theChart3dDataView
class, then surface, bar, or scatter plots can be drawn. The previous chapter dealt with surface charts and bar charts; this chapter deals with scatter plots.A scatter plot can be drawn using grid data, but the most usual way of providing data to a scatter plot is to provide the
elevationDataSource
with point data. This type of data supports an arbitrary number of series, each containing an arbitrary number of points.An object can be a point data source if it implements the
Chart3dPointDataModel
. When a point data source is passed to aChart3dDataView
object, the data is extracted and stored in an internal point data object of typeChart3DPointData
. This object can be retrieved via theelevationData
property ofChart3dDataView
.More sophisticated point data sources can implement the
LabelledChart3dPointDataModel
,EditableChart3dDataModel
,HoleValueChart3dDataModel
, and theChart3dDataManager
interfaces.Please see Data Sources, in Chapter 5, for further details.
Each series can have a symbol that makes it distinct from that of the other series. When a chart of type
SCATTER
is used in conjunction with grid data, each grid point will define a point in the scatter plot.
4.2 Three Basic Types of Scatter Plots
JClass Chart 3D offers three basic types of scatter plots: 3D scatter plots, 3D scatter plots with drop lines, and 2D scatter plots. (3D scatter plots with drop lines are not currently available in the Java 3D API version of JClass Chart 3D.)
Figure 20 : Scatter Plot examples.
Drop lines are lines drawn from each point on the 3D scatter plot down to the matching (x,y) position on the Z-axis origin of the plot cube. The drop line joins the point (x, y, z) to the matching point (x, y, origin). Drop lines are not used for 2D scatter plots. To draw drop lines on 3D scatter plots, set the
dropLines
property of theJCScatter
class totrue
.2D scatter plots use only the X- and Y-values, and ignore the z components. They are "flat" charts. These plots are created by setting both the meshed and the shaded properties of the
JCElevation
object tofalse
.
4.3 Controlling Symbol and Drop Line Style
4.3.1 Point Data
The style of symbols and drop lines used in scatter plots is determined on a per series basis. The
chartStyle
property of theChart3dPointSeries
specifies the line and symbol style information for a series.A list of
Chart3dPointSeries
objects can be obtained from the series property of the internal point data object. This object, of typeChart3dPointData
, can be retrieved via the data view'selevationData
property.Here is a code sample that changes the line style of the third series of a scatter plot. This code sample assumes that a point data source has already been set on the data view.
Chart3dPointData pointData=(Chart3dPointData)dataView.getElevationData();
ArrayList series=pointData.getSeries();
Chart3dPointSeries pointSeries=(Chart3dPointSeries)series.get(2);
JCChartStyle chartStyle=pointSeries.getChartStyle();
chartStyle.setLineStyle(new JCLineStyle(2, color.blue, JCLineStyle.SOLID));Line pattern, color, and width are controlled by the chart style's
LineStyle
property, and symbol color, size, and pattern by the chart style'sSymbolStyle
property.
4.3.2 Grid Data
If either the
zoned
orcontoured
properties ofJCContour
aretrue
, the symbol color and style, along with the dropline style, will be chosen through the appropriatecontourStyle
for the contour level to which the point belongs.Note: This makes use of the
JCContourStyle
class'lineStyle
andsymbolStyle
properties.If both
zoned
andcontoured
arefalse
, the symbol color and style, along with the dropline style, will be chosen through thechartStyle
property if the internalChart3dGridData
object is associated with the grid data.
4.4 Chart Styles
In a scatter plot, how a data value looks when it is displayed (for instance, color, line pattern, symbol style, line thickness, and so forth) depends on the chart style that has been defined for that data value. For example, the values in the third series of data will be rendered on screen using the chart style associated with the third series of the point data.
4.4.1 Default Chart Styles
When a new
Chart3dPointSeries
object is created, a defaultchartStyle
is created that possesses default line and symbol styles. The defaults are cycled, so consecutive calls will return different chart styles. A user may choose to override these defaults.The
JCChartStyle
class has two main components: aJCSymbolStyle
object that stores symbol information and aJCLineStyle
object that stores line style information. For convenience, the user can either set or get thesymbolStyle
orlineStyle
properties of theJCChartStyle
class, or the user can set the individualsymbolStyle
orlineStyle
properties directly on thechartStyle
.For example, the following line of code:
chartStyle.setLineWidth(2);will change the line width of the
chartStyle
'slineStyle
object.The
JCChart3dStyle data
structure contains all the information about how a set of data will be represented graphically. The properties are broken down as follows:The following method will print out the symbol size being used for the series of data, and double it:
public void double SymbolSize (Chart3dDataView dataView, int seriesIndex)
{
Chart3dPointData pointData=(Chart3dPointData)dataView. getElevationData();
ArrayList series=pointData.getSeries();
Chart3dPointSeries pointSeries=(Chart3dPointSeries)series(seriesIndex);
JCChartStyle chartStyle=pointSeries.getChartStyle();
system.out.println("symbol size:"+chartStyle.getSymbolSize());
chartStyle.setSymbolStyle(2*chartStyle.getSymbolSize());
}
4.4.2 Grid Data
For grid data, the
JCSymbolStyle
object and theJCLineStyle
object that determine how each point is drawn are obtained from either aJCContourStyle
object or aJCChartStyle
object. See Grid Data, in Chapter 4, for more information.