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
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);
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);
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.
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.
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.
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.