WaterfallChartModel: Bars

A WaterfallChartModel can modify the appearance of bars in the chart. For example, it can change the bar width, the space between bars, and the bar colors.

When changing bar appearance, the BarWidth, BarWidthSpace, and GrowBarWidthEnabled properties, along with the chart's DisplayPolicy property, all play together to determine what visible width is actually assigned to the bar elements.

Generally, to change the bar appearance,

The following code fragment sets a 7-pixel bar width and a 5-pixel space between bars:

 
WaterfallChartModel graphModel=waterfallChart.getGraphModel();
  graphModel.setGrowBarWidthEnabled(true);
  graphModel.setBarWidth(new BaseLength(7,"px"));
  graphModel.setBarWidthSpace(new BaseLength(5,"px"));

To modify the bar colors,

For example, the following code fragment specifies red, black, and green as the colors to use for bars, based on the values of the response variable:


// style bars according to the values of the response variable
dataModel.setStyleByVariable(dataModel.getResponseVariable());

// set a palette for three continuous colors
waterfallfallChart.getGraphModel().setColorPaletteType(GraphConstants.COLOR_PALETTE_THREE_COLOR_CONTINUOUS);

// associate start, neutral, and end colors with the data elements (bars)
waterfallfallChart.getGraphModel().getDataElementStyles().setContinuousFillThreeColorStartColor(Color.red);
waterfallfallChart.getGraphModel().getDataElementStyles().setContinuousFillThreeColorNeutralColor(Color.black);
waterfallfallChart.getGraphModel().getDataElementStyles().setContinuousFillThreeColorEndColor(Color.green);

Example
Changing Bar Width: Swing-based code, Servlet-based code

WaterfallChartModel: Display Properties

In addition to changing the bar appearance, the WaterfallChartModel can be used to change other general display properties, as shown in the following code fragment:


javax.swing.table.TableModel tableModel = <...>;  // some TableModel data
WaterfallChartTableDataModel dataModel = new WaterfallChartTableDataModel(tableModel);

// Create a WaterfallChart
   WaterfallChart waterfallChart = new WaterfallChart(dataModel,graphStyle);

// Set a title
   waterfallChart.getTitle1().setText("Sample WaterfallChart");

// Get the WaterfallChart's graphModel
   WaterfallChartModel waterfallChartModel = waterfallChart.getGraphModel();

// Set a height for an initial bar
   waterfallChartModel.setInitialBarHeight(75.0);

// Set a fill style for both the initial and the final bars
   FillStyle barcolor = new FillStyle(Color.red);
   waterfallChartModel.setInitialBarFillStyle(barcolor) ;
   waterfallChartModel.setFinalBarFillStyle(barcolor) ;

// Change the bar outline color for all bars
   waterfallChartModel.getDataElementStyles().getOutlineLineStyle().setColor(Color.red);

// Set some response-axis text properties
   waterfallChartModel.getResponseAxisModel().getLabelTextStyle().setFont(new Font("TimesRoman",Font.BOLD,18));
   waterfallChartModel.getResponseAxisModel().getLabelTextStyle().setColor(Color.red);
   waterfallChartModel.getResponseAxisModel().getValueTextStyle().setFont(new Font("TimesRoman",Font.BOLD,14));

Rather than changing individual properties, it may be easier to use the WaterfallChart to set a graph style, which makes it easier to manage multiple display properties.

WaterfallChartModel: Line Styles

A WaterfallChartModel can be used to modify the line style (color, width, visibility, ...) of any of the various lines in a WaterfallChart.

The following table shows the lines you can set and the method(s) to call to access and/or set the line attributes.

To change ... Call ...
waterfall outlines getDataElementStyles().setOutlineLineStyle(LineStyle)
category axis lines
(axis, grid, tick, and reference lines)
getCategoryAxisModel() and use the returned AxisModel to set axis line style, grid line styles, major tick styles, minor tick styles, and reference line models
response (left) axis lines
(axis, grid, tick, and reference lines)
getResponseAxisModel() and use the returned AxisModel to set axis line style, grid line styles, major tick styles, minor tick styles, and reference line models
legend frame getLegendModel().setFrameLineStyle(LineStyle)
missing-values lines getDataElementStyles().setMissingLineStyle(StrokeLineStyle)
column axis lines
(available when ColumnVariable role is used)
getColumnAxisModel().setFrameLineStyle(LineStyle)
row axis lines
(available when RowVariable role is used)
getRowAxisModel().setFrameLineStyle(LineStyle)
frame lines around column/row cells
(available when ColumnVariable and/or RowVariable roles are used)
setFrameLineStyle(LineStyle)

The following code fragment specifies a 3-point red line for bar outlines:


WaterfallChartModel graphModel=waterfallChart.getGraphModel();

LineStyle lineStyle=new LineStyle(
          java.awt.Color.red,
          new com.sas.measures.BaseLength(3, "pt"),
          com.sas.components.GraphConstants.TRUE);

graphModel.getDataElementStyles().setOutlineLineStyle(lineStyle);
Example
Change Axis Lines: Swing-based code

WaterfallChartModel: Behavior

WaterfallChartModel properties are bound properties. Modifying a property triggers a PropertyChangeEvent. The WaterfallChart asynchronously updates when a PropertyChangeEvent is received from the WaterfallChartModel. Similarly, modifying a property in any of the WaterfallChartModel's contained models triggers a PropertyChangeEvent. A PropertyChangeEvent from contained models will bubble up to cause a PropertyChangeEvent to be fired from the WaterfallChartModel.

For example, the following call

 
waterfallChartModel.getColorLegendModel().getValueTextStyle().setColor(java.awt.Color.yellow);

would cause the legend's value text style model to fire a "color" PropertyChangeEvent, causing legend model to fire a "valueTextStyle" PropertyChangeEvent, causing the WaterfallChartModel to fire a "colorLegendModel" PropertyChangeEvent. This bubbling up of events enables the graph or any other listener to manage updates at a higher level of containment.