The main responsibility of a RiskMapPlotTableDataModel is to determine which data variables are used in the risk map and what role each variable plays. The primary roles are
Each of these primary roles are assigned to a PlotVariable. A unique plot element (marker) is produced for each unique X,Y value pair or combination of value pairs when other variable roles are specified.
For example, the following code fragment assigns the X and Y variable roles to variables named "Systolic Blood Pressure" and "Blood Sugar":
// Create a data source
javax.swing.table.TableModel dataTable = <...>;
// Create a data model and attach the data source to it
RiskMapPlotTableDataModel dataModel =
new RiskMapPlotTableDataModel();
dataModel.setModel(dataTable);
// Assign the X and Y variable roles. Assignments
// assume the data source contains these variables.
dataModel.setXVariable(new PlotVariable("Systolic Blood Pressure"));
dataModel.setYVariable(new PlotVariable("Blood Sugar"));
// Set up the desired risk map, in this case, a SimpleRiskMap
SegmentedRangeModel xRange = SegmentedRangeModel.
newSegmentedRangeModel(new double[]{0, 120, 135, 160, 200});
SegmentedRangeModel yRange = SegmentedRangeModel.
newSegmentedRangeModel(new double[]{0, 100, 120, 160, 400});
SimpleRiskMap simpleRiskMap = new SimpleRiskMap(xRange, yRange,
new Color[]{Color.GREEN,Color.YELLOW, Color.ORANGE, Color.RED},
SimpleRiskMap.TYPE_BLOCK);
// Construct a RiskMapPlot that uses the data model and risk map
RiskMapPlot riskMapPlot = new RiskMapPlot(dataModel);
riskMapPlot.getGraphModel().setRiskMap(simpleRiskMap);
The ShapeVariable, SizeVariable, and ColorVariable roles can be used to control the shape, size, and color of the markers in any RiskMapPlot. These roles are assigned to Variables, and the assignment would resemble the following:
dataModel.setColorVariable(new Variable("CMarker"));
The variables that are assigned these roles must have the appropriate information. For example, a variable that is assigned the Color role must store valid color values.
As an alternative to using a variable role to change plot markers, you can use a plot's RiskMapPlotModel to
To label plot points, use the BottomMarkerLabelVariable or TopMarkerLabelVariable roles. Either role can be assigned to a data column that is used for X or Y variables in the program code. In the following code fragment, the values from a data column named Year are used to label plot points above the plot markers:
dataModel.setTopMarkerLabelVariable(new Variable("Year"));
To identify data groups according to the values of a ClassificationVariable, assign the GroupVariable role to the appropriate classification variable.
For example, a variable named Patient might be assigned the Group role so that the plot markers reveal which points came from a data row with patient names. The assignment would resemble the following:
dataModel.setGroupVariable(new ClassificationVariable("Patient"));
Markers of different shape and color are used to represent each unique value of the Group variable.
The following table summarizes the RiskMapPlotTableDataModel variable roles and the type of data each role supports.
| Variable Role | Class Type | |||
|---|---|---|---|---|
| XVariable* Assigns horizontal-axis variable |
PlotVariable | |||
| YVariable* Assigns left vertical-axis variable |
PlotVariable | |||
| AuxiliaryVariable Array of variables that are not represented in the chart but are included among the variables that are passed in the events on the RiskMapPlot data elements |
Variable[] | |||
| BottomMarkerLabelVariable Assigns labels below the plot markers |
Variable | |||
| ColorVariable Assigns marker colors |
Variable | |||
| ColumnVariable Aligns multiple charts in columns |
ClassificationVariable | |||
| DataTipVariable Array of variables whose values will be displayed in the data tips |
Variable[] | |||
| GroupVariable Associates markers with data groups |
ClassificationVariable | |||
| RowVariable Aligns multiple charts in rows |
ClassificationVariable | |||
| ShapeVariable Assigns marker shapes |
Variable | |||
| SizeVariable Assigns marker sizes |
Variable | |||
| SortVariable Defines the order in which plot points are connected when a line interpolation is applied |
Variable | |||
| TopMarkerLabelVariable Assigns labels below the plot markers |
Variable | |||
| * required variable | ||||
To generate a graph, a RiskMapPlot needs data columns for the X and Y variable roles.
If the Y role is not assigned in the program code, a RiskMapPlot selects the first numeric column found in the RiskMapPlotTableDataModel and uses it as its Y variable. If there is no numeric column in the data, then it selects the first string column.
If the X role is not assigned in the program code, a RiskMapPlot selects the first numeric column which is different from Y and uses it as the X variable. If no valid numeric column is found, then it selects the first string column different from Y and uses it as X.
This default behavior occurs only when the X and/or Y role is not assigned. If either role is assigned to a variable that does not exist in the data, the RiskMapPlot cannot display a graph.
A RiskMapPlotTableDataModel fires property change events when
For example, if the name property is changed in the PlotVariable that has been assigned the XVariable role, the RiskMapPlotTableDataModel fires a ProeprtyChangeEvent stating that the XVariable has changed.
When variable roles are assigned, the RiskMapPlotTableDataModel does not confirm that the variables exist in the TableModel. Thus, assigning a non-existent data column to a variable role may mean that the RiskMapPlot cannot display a graph. For example, if the XVariable role is assigned to a Product column but the TableModel does not contain a Product column, then the RiskMapPlot fails to produce a graph.
If the XVariable and YVariable roles are correctly assiged to existing variables but another role is incorrectly assigned, the RiskMapPlot displays a graph without the incorrect role. For example, if the XVariable and YVariable roles are correctly assigned but the ColumnVariable role is not, a graph using the X and Y roles is generated, but the Column role is ignored.