The minimum specification for a RiskMapPlot requires a valid data model. Generally the data model should assign the X and Y variable roles to PlotVariables in the data. If the X role is not assigned, the RiskMapPlot automatically assigns it to the first numeric column found in the data model, or to the first string column if the model has no numeric column. If the Y role is not assigned, the RiskMapPlot selects the first numeric column that is different from X and uses it as the Y variable. If no valid numeric column is found, then it selects the first string column that is different from X and uses it in the Y role.
The RiskMapPlot also requires that you construct an image background for the plot from a class that descends from the AbstractRiskMap class. The component is delivered with the following descendant classes:
You can use each of these classes as is, or enhance them. You can also create a descendant class from AbstractRiskMap that meets your specific needs.
If multiple variables are assigned the X role or the Y role, a separate set of data points is generated for each variable. If X and Y both have multiple variables, then a separate point is produced for each pair of X and Y values. For example, if X has values x1, x2, x3 and Y has values y1, y2, y3, then there will be three points: one for (x1, y1), another for (x2, y2), and a third for (x3, y3). With multiple variables assigned X and/or Y roles, all plot points use the same set of axes. If a group variable is specified, a different color and marker shape is used for each plot generated by the plot values.
If ColumnVariable and/or RowVariable roles are specified, a separate plot is produced for each classification value, and each plot has its own axes. The plots are arranged in a column for the ColumnVariable role, in a row for the RowVariable role, or in a graph matrix if both columns and rows are used. In the graph matrix, a separate graph is produced for each (column, row) value pair. You can control the arrangement and text of the labels and values that identify the column and row axes.
A risk map's data properties are defined in a data model that descends from RiskMapPlotDataModel, an abstract class whose subclass provides a handle to the data and determines the number and arrangement of data elements (plot points). RiskMapPlotDataModel has the following subclass:
A RiskMapPlot's individual display properties can be set by calling the RiskMapPlot's getGraphModel() method, which returns a RiskMapPlotModel that can be used to set the desired properties. The RiskMapPlotModel class contains
If the risk map you construct from the AbstractRiskMap descendant supports it, you can set a RiskMapPlot's display properties by applying a pre-defined GraphStyle to the plot. A graph style sets many of the graph's visual characteristics, such as its use of colors, fonts, background, transparency, drop shadows, and more. A graph style can be used as is or modified through the GraphStyle class.
A graph style can be specified as an argument on a RiskMapPlot's constructor. Or, it can be applied to an existing plot by calling the RiskMapPlot's applyGraphStyle() method as follows:
RiskMapPlot riskMapPlot = new RiskMapPlot();
riskMapPlot.applyGraphStyle(new GraphStyle(GraphStyle.STYLE_SCIENCE);
Applying a GraphStyle to a graph propagates the GraphStyle's properties onto all applicable graph properties, including those in the graph model.
Rather than use the style as is, you can modify it before applying it. Modifying the style definition is typically easier and more convenient than modifying the graph's individual display properties. For example, the GraphStyle class contains only a single set of value text propertes. After applying the modified style, you can still adjust individual properties through the graph model.
The following code fragment modifies a graph style before applying it to a graph, and then uses the graph model to adjust an individual property.
// Create and modify a graph style
GraphStyle graphStyle = new GraphStyle(GraphStyle.STYLE_SCIENCE);
graphStyle.getValueTextStyle().setColor(Color.darkGray);
graphStyle.getValueTextStyle().setFont(new java.awt.Font("Arial",Font.BOLD,14));
// Apply the modified graph style to a plot
RiskMapPlot riskMapPlot = new RiskMapPlot();
riskMapPlot.applyGraphStyle(graphStyle);
// Set the category axis value text to black
RiskMapPlotModel graphModel=riskMapPlot.getGraphModel();
graphModel.getXAxisModel().getValueTextStyle().setColor(Color.black);
Whether you set a graph style or individual display properties, the new display settings override any previous settings that were applied to the graph. For example, if a gray background has been set on a graph, and then a style is applied to that same graph, the style's background replaces the previously set gray background.
The RiskMapPlot component supports four titles and two footnotes, each with its own display attributes. To display multiple lines of text with the same attributes, use the line-end character (\n) in the specified text string.
To assign a title or footnote,
The easiest way to set the text for a title or footnote is to get the plot's title or footnote property and set its text as follows:
riskMapPlot.getTitle1().setText("Line One\nLine Two");
To change the text attributes for a title or footnote, set the attributes on a NoteModel and assign the NoteModel to the appropriate title or footnote. The following example sets the title "Product Revenue" and displays it in blue, using a 24-point TimesRoman font with a drop shadow.
NoteModel myTitle = new NoteModel( "Weight Study" );
myTitle.getTextStyle().setColor(Color.blue);
myTitle.getTextStyle().setFont(new java.awt.Font("TimesRoman",Font.PLAIN,24));
myTitle.getTextStyle().getShadowStyle().setVisible(true);
// Create the graph and assign the title
RiskMapPlot riskMapPlot = new RiskMapPlot();
riskMapPlot.setTitle1( myTitle );
The RiskMapPlot asynchronously updates when a PropertyChangeEvent is received from any of its models (DataModel, GraphModel or NoteModels).