WaterfallChart: Minimum Specification

The minimum specification for a WaterfallChart requires a valid data model. Generally the data model should assign the Category variable role to a ClassificationVariable, but if the role is not assigned, the WaterfallChart automatically assigns it to the first string column found in the data model, or to the first numeric column if the model has no string column. If a response variable is not specified, the data elements (bars) reflect the category variable’s frequency count.

Example
Basic Requirements for Creating a WaterfallChart: Swing-based code, Servlet-based code

WaterfallChart: Functional Overview

The Independent variable in the chart is treated as a Classification variable. Each category of the Independent variable is displayed as a bar. If there are multiple response variables, the bars from each response are displayed side-by-side for ease of comparison. For example, if response variables for first- and second-quarter transactions are charted, the bars representing the quarterly transactions for each classification value are displayed side-by-side. Basic statistics such as Sum, Mean, and Frequency are supported, and you can control the labels that are displayed for each variable.

The component can display charts in 2D or 3D view. It can style the bars, based on the value of a specified variable, and it can use the values of one or more classification variables to produce multiple charts. The charts can be arranged in columns (using the ColumnVariable role), rows (using the RowVariable role), or a graph matrix (using both roles). A separate chart is generated for each unique column or row value, or for each value pair when both a column and row variable are specified. You can control the arrangement and text of the labels and values that identify the column and row axes.

WaterfallChart: Data Access

A waterfall chart's data properties are defined in a data model that descends from WaterfallChartDataModel, an abstract class whose subclasses provide a handle to the data and determine the number and arrangement of data elements (bars). WaterfallChartDataModel has the following subclasses:

WaterfallChart: Display Properties

A WaterfallChart's individual display properties can be set by calling the WaterfallChart's getGraphModel() method, which returns a WaterfallChartModel that can be used to set the desired properties. The WaterfallChartModel class contains

Although modifying the WaterfallChartModel provides considerable control, it can be tedious to modify properties individually. For example, graphs distinguish between different types of text, such as label text, value text, data-label text, and title text. The text might also apply to different locations, such as the response axis, category axis, and legend. Whereas the WaterfallChartModel can independently control these different text types and locations, doing so requires you to apply the same properties to all applicable locations.

An easier way to set a WaterfallChart's display properties is to apply a pre-defined GraphStyle to the chart. 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 WaterfallChart's constructor. Or, it can be applied to an existing chart by calling the WaterfallChart's applyGraphStyle() method as follows:


WaterfallChart waterfallChart = new WaterfallChart();
waterfallChart.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 properties. 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 chart
WaterfallChart waterfallChart = new WaterfallChart();
   waterfallChart.applyGraphStyle(graphStyle);

// Set the category axis value text to black
WaterfallChartModel graphModel=waterfallChart.getGraphModel();
   graphModel.getCategoryAxisModel().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 and yellow bar outlines have been set on a graph, and then a style is applied to that same graph, the style's background and outline settings replace the previously set gray background and yellow outlines.

WaterfallChart: Titles and Footnotes

The WaterfallChart 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 chart's title or footnote property and set its text as follows:


waterfallChart.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 "Transaction Amounts" and displays it in blue, using a 24-point TimesRoman font with a drop shadow.


NoteModel myTitle = new NoteModel( "Transaction Amounts" );
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
WaterfallChart waterfallChart = new WaterfallChart();
waterfallChart.setTitle1( myTitle );

WaterfallChart: Usage Examples

The following example fragment graphs company transactions for various income and expense categories. It uses relational data from a Swing TableModel that contains a string column of IDs that represent the transaction category and a numeric column of Transactions that show the transaction amount. To enhance the graph's appearance, the example assigns the "Magnify" GraphStyle to the chart.


javax.swing.table.TableModel mySalesData = <...>;

// Create the WaterfallChart's data model.
WaterfallChartTableDataModel waterfallChartDataModel = new WaterfallChartTableDataModel( myData );
waterfallChartDataModel.setCategoryVariable( new ClassificationVariable("ID") );
waterfallChartDataModel.setResponseVariable( new AnalysisVariable("Transaction") );

// Create the WaterfallChart applying the data model and the "Magnify" GraphStyle
WaterfallChart waterfallChart = new WaterfallChart( waterfallChartDataModel, new GraphStyle(GraphStyle.STYLE_MAGNIFY) );
waterfallChart.getTitle1().setText("Transaction Amounts");
waterfallChart.getFootnote1().setText("Company Confidential");

WaterfallChart: Behavior

The WaterfallChart asynchronously updates when a PropertyChangeEvent is received from any of its models (DataModel, GraphModel or NoteModels).