BarLineChartModel: Bars

A BarLineChartModel can modify the appearance of bars in the chart. For example, it can change the bar width and fill style.

When changing bar width, the BarWidth, BarWidthBuffer, 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 width,

The following code fragment sets a bar width of .75 inches:

 
BarLineChartModel graphModel=barLineChart.getGraphModel();
graphModel.setGrowBarWidthEnabled(true);
graphModel.setBarWidth(new BaseLength("0.75in"));

To modify the fill style for bars,

  1. create a FillStyle array with the desired properties
  2. call the BarLineChartModel's getDataElementStyles() method to retrieve the DataElementStyles that encapsulate the visual properties of the bars
  3. call the DataElementStyles' setFillStyles() method to assign the defined MarkerStyle to the plot.

For example, the following code fragment specifies red, green, and blue bars:

 
FillStyle[] fillStyle=new FillStyle[] {
              new FillStyle(java.awt.Color.red),
              new FillStyle(java.awt.Color.green),
              new FillStyle(java.awt.Color.blue)
};
BarLineChartModel graphModel=barLineChart.getGraphModel();
graphModel.getDataElementStyles().setFillStyles(fillStyle);

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

BarLineChartModel: Display Properties

In addition to changing the bar width, the BarLineChartModel can be used to change other general display properties, as shown in the following example:


// Get a BarLineChart
   BarLineChart barLineChart = new BarLineChart();
 
//Get my barLineChart's graphModel
  BarLineChartModel barLineChartModel = barLineChart.getGraphModel();

// Assign background color
   barLineChartModel.getBackgroundFillStyle().setFillType(FillStyle.FILL_TYPE_SOLID_COLOR);
   barLineChartModel.getBackgroundFillStyle().setSolidFillColor(Color.lightGray);

// Assign data element outline color
   barLineChartModel.getDataElementStyles().getOutlineLineStyle().setColor(Color.darkGray);
 
// Set the axis line colors
   barLineChartModel.getResponseAxisModel().getAxisLineStyle().setColor(Color.darkGray);
   barLineChartModel.getCategoryAxisModel().getAxisLineStyle().setColor(Color.darkGray);

// Set the axis value font
   java.awt.Font myValueFont = new java.awt.Font("TimesRoman",Font.PLAIN,12);
   barLineChartModel.getResponseAxisModel().getValueTextStyle().setFont(myValueFont);
   barLineChartModel.getCategoryAxisModel().getValueTextStyle().setFont(myValueFont);

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

BarLineChartModel: Line Styles

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

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 ...
bar and marker outlines getDataElementStyles().setOutlineLineStyle(LineStyle)
plot line(s) getDataElementStyles().setLineStyles(StrokeLineStyle[] )
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
response2 (right) axis lines
(axis, grid, tick, and reference lines)
getResponse2AxisModel() and use the returned AxisModel to set axis line style, grid line styles, major tick styles, minor tick styles, and reference line models
response axis baseline for bars setResponseAxisBaselineModel(ReferenceLineModel)
response2 axis baseline for bars setResponse2AxisBaselineModel(ReferenceLineModel)
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 dashed line for the plot line:


BarLineChartModel graphModel=barLineChart.getGraphModel();

StrokeLineStyle[] lineStyle=new StrokeLineStyle[] {
  new StrokeLineStyle(StrokeLineStyle.SASGRAPH_LINE15,
      Color.red,
      new BaseLength(3, "pt"),
      GraphConstants.TRUE)
};

graphModel.getDataElementStyles().setLineStyles(lineStyle);

Example
Change the Plot Line: Swing-based code
Change the Axes: Swing-based code
Set a Response Baseline: Swing-based code

BarLineChartModel: Behavior

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

For example, the following call

 
barLineChartModel.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 BarLineChartModel 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.