AreaBarChartTableDataModel: Basic Charts

The main responsibility of an AreaBarChartTableDataModel is to determine which data variables are used in the chart and what role each variable plays. An AreaBarChartTableDataModel's variable roles are

CategoryVariable
Specifies a classification variable whose values determine the number and arrangement of bars in the chart. A unique bar element is produced for each unique classification value or combination of values when other variable roles are specified. Because an AreaBar chart needs to organize the category variable's data values into groups (typically called bins), the CategoryVariable role uses a ClassificationVariable, which is designed to manage and sort categorical values.
HeightVariable, WidthVariable
Specify analysis variables whose values determine the height and width of each bar. Each role uses an AnalysisVariable because the class associates a statistical computation with a variable instance.
SubgroupVariable
Optional role. Specifies a classification variable whose values divide the bars into segments.

The following code fragment shows a basic specification:

 
// Create a data source that must contain a string column
// named EnergyType and a numeric column named Produced
   javax.swing.table.TableModel dataTable = <...>;

// Create an AreaBarChart instance and a data source 
   AreaBarChart areaBarChart=new AreaBarChart();

// Create a data model and attach the data source
   AreaBarChartTableDataModel dataModel=
      new AreaBarChartTableDataModel();
   dataModel.setModel(dataTable);

// Assign variable roles to appropriate variables
   dataModel.setCategoryVariable(
      new ClassificationVariable("GroupVar"));
   dataModel.setHeightVariable(
      new AnalysisVariable("HeightVar"));
   dataModel.setWidthVariable(
      new AnalysisVariable("WeightVar"));

// Assign the data model to the AreaBarChart
   areaBarChart.setDataModel(dataModel);

Example
Basic Requirements for Creating an AreaBar Chart

AreaBarChartTableDataModel: Data Summarization and Statistic Calculation

When a data model is assigned to an AreaBarChart, the chart summarizes the data before displaying it. During summarization

The following statistics are the default calculations:

The AnalysisVariable constructor can be used to specify a statistic to calcuate. The following code fragment specifies a mean:

 
AnalysisVariable height=new AnalysisVariable(
  "Var1"                            // column for Response role
  ,GraphConstants.STATISTIC_MEAN    // statistic to calculate
);
AreaBarChartTableDataModel dataModel=new AreaBarChartTableDataModel();
dataModel.setHeightVariable(height);

Example
Specifying a Statistic in an AreaBarChart

AreaBarChartTableDataModel: Data Subgroups

To identify data subgroups according to the values of a ClassificationVariable, assign the SubroupVariable role to the appropriate classification variable. Each bar in the chart is then divided into segments that represent the values of the Subgroup variable.

For example, if the bars in a chart represent energy production, a variable named Year might be assigned the Subgroup role. The Subgroup role would cause each bar to be subdivided into segments that represent each year's energy production. The assignment would resemble the following:

 
dataModel.setSubgroupVariable(new ClassificationVariable("Year"));

Different colored bar segments are used to represent each unique value of the Subgroup variable.

Example
Displaying Data Subgroups in a Bar Chart

AreaBarChartTableDataModel: Behavior

To generate a graph, an AreaBarChart needs a data column for the CategoryVariable role. If the role is not assigned in the program code, an AreaBarChart selects the first string column found in the AreaBarChartTableDataModel and uses it as its Category variable. If there is no string column in the data, then it selects the first numeric column.

This default behavior occurs only when the Category role is not assigned. If the role is assigned to a variable that does not exist in the data, the AreaBarChart cannot display a graph.

If the HeightVariable or WidthVariable roles are not assigned in the program code, then the bar heights and widths represent a frequency count of the Category values. When either of the roles is assigned, then the default statistic for it is the sum of the response values for each category value.

AreaBarChartTableDataModel: Events

An AreaBarChartTableDataModel fires property change events when

For example, if the name property is changed in the ClassificationVariable that has been assigned the CategoryVariable role, the AreaBarChartTableDataModel fires a ProeprtyChangeEvent stating that the CategoryVariable has changed.

AreaBarChartTableDataModel: Error Handling

When variable roles are assigned, the AreaBarChartTableDataModel 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 AreaBarChart cannot display a graph. For example, if the CategoryVariable role is assigned to a Product column but the TableModel does not contain a Product column, then the AreaBarChart fails to produce a graph.

If the CategoryVariable role is correctly assiged to an existing variable but another role is incorrectly assigned, the BarChart displays a graph without the incorrect role. For example, if the CategoryVariable role is correctly assigned but the SubgroupVariable role is not, a graph using the Category role is generated, but the Subgroup role is ignored.