LineChartTableDataModel: Basic LineCharts

The main responsibility of a LineChartTableDataModel is to determine which data variables are used in a LineChart and what role each variable plays. The primary roles are

CategoryVariable
Specifies a a classification variable whose values are represented along the horizontal axis. Because a LineChart 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.
ResponseVariable
Specifies an analysis variable whose values are represented along the left vertical axis. The role uses an AnalysisVariable or AnalysisVariableList because these classes associate a statistical computation with a variable instance.
Response2Variable
Assigns a second response variable, whose values are represented along the right vertical axis.

A unique plot point is produced for each unique Category,Response value pair or combination of value pairs when other variable roles are specified, and by default those points are joined by an interpolated line.

For example, the following code fragment graphs monthly temperatures by assigning the Category and Response variable roles to variables named Month and Temp:

 
// Create a data source
   javax.swing.table.TableModel dataTable = <...>;

// Create a data model and attach the data source to it
   LineChartTableDataModel dataModel =
          new LineChartTableDataModel();
   dataModel.setModel(dataTable);
     
// Assign the Category and Response variable roles.
// Assignments assume that the data source contains
// a column named Month and a column named Temp.
   dataModel.setCategoryVariable(new ClassificationVariable("Month"));
   dataModel.setResponseVariable(new AnalysisVariable("Temp"));

// Create a LineChart and attach the data model to it
   LineChart lineChart = new LineChart();
   lineChart.setDataModel(dataModel);

When the model is assigned to a LineChart, one plot point is produced for each (Category, Response) value pair. If the Response2 role is assigned in the model, a plot point is also produced for each (Category, Response2) value pair.

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

See Also: Valid Variable Roles

LineChartTableDataModel: Plot Markers

By default, plot markers are displayed and an interpolated line that joins plot points is displayed. To change the default display, you can get the plot's LineChartModel and use it to

Example
Changing Markers in a LineChart: Swing-based code, Servlet-based code

LineChartTableDataModel: Labels for Plot Points

To label plot points above or below the plot markers, use the OutsideMarkerLabelVariable role.

The OutsideMarkerLabelVariable variable role can be assigned to a data column that is used to create a Variable in the program code. In the following code fragment, the values from a data column named Temp are used to label plot points:

 
dataModel.setOutsideMarkerLabelVariable(new Variable("Temp"));

Example
Label Plot Points: Swing-based code

LineChartTableDataModel: Data Summarization and Statistic Calculation

When a data model is assigned to a LineChart, 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 response=new AnalysisVariable(
  "Var1"                            // column for Response role
  ,GraphConstants.STATISTIC_MEAN    // statistic to calculate
);
LineChartTableDataModel dataModel=new LineChartTableDataModel();
dataModel.setResponseVariable(response);

By default, a LineChart summarizes the data, even if the TableModel's data values have already been summarized. When the values in the data source have already been summarized, you can improve performance by turning off data summarization. Do this by setting the StatisticEnabled boolean to false as follows:

 
LineChartTableDataModel dataModel=new LineChartTableDataModel();
dataModel.setStatisticEnabled(false);

Example
Specifying a Statistic in a Line Chart: Swing-based code

LineChartTableDataModel: Numeric Categorizations

By default, a discrete categorization is performed when a numeric data column is specified for the CategoryVariable role. The format parameter on the ClasificationVariable's constructor can be used to specify the type of categorization (or midpointing) operation to use.

For example, for a numeric data column named Sample, the following code fragment formats the numeric values into categories Initial, Interim, and Final, and then specifies the numeric variable for the Category role:

 
        try {
             com.sas.text.SASUserDefinedFormat.createFormat(
                 "value myFormat 1 - 2 = 'Initial'"
                 +              "3 - 4 = 'Interim'"
                 +              "5 - 6 = 'Final'");
            } catch (java.text.ParseException e) {
        java.lang.System.out.println("error=" + e.getMessage());
      }
ClassificationVariable myFormattedVar=
  new ClassificationVariable("Sample", "myFormat");

LineChartTableDataModel dataModel=new LineChartTableDataModel();
dataModel.setCategoryVariable(myFormattedVar);

Example
Specifying a Numeric Category Variable: Swing-based code

LineChartTableDataModel: Data Subgroups

To generate separate plot lines according to the values of a ClassificationVariable, assign the SubgroupVariable role to the appropriate classification variable.

For example, a variable named City might be assigned the Subgroup role so that separate plot lines are generated for different city temperatures. The assignment would resemble the following:

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

Different colored lines are used to represent the values of the Subgroup variable.

To fill the areas between plot lines, use a LineChartModel to call the setFillAreaEnabled() method with the argument value true.

Examples
Displaying Data Subroups in a LineChart: Swing-based code, Servlet-based code
Filling Plot Areas: Swing-based code, Servlet-based code

LineChartTableDataModel: Data-Error Values

A LineChartTableDataModel does not support error values in the data model. If a constructor for an AnalysisVariable that is used in the chart specifies high or low error values, those error values are not used in the chart.

LineChartTableDataModel: Multiple Response Variables

Multiple Response variables can be plotted against the same Category variable by adding the variables to an AnalysisVariableList, and then assigning that list rather than an individual variable to the Response role.

The following code fragment assigns the Category role to variable X, and the Response role to variables named Y1 and Y2:

 
dataModel.setCategoryVariable(
  new ClassificationVariable("X"));

AnalysisVariableList multiResponse=new AnalysisVariableList(
  new AnalysisVariable[] {
      new AnalysisVariable("Y1"),
      new AnalysisVariable("Y2")
  } );
dataModel.setResponseVariable(multiResponse);

For each value of the category variable, a plot point is generated for each response variable's corresponding values.

Example
Multiple Responses, Same Axes: Swing-based code, Servlet-based code

LineChartTableDataModel: Multiple LineCharts in Columns and/or Rows

Separate LineCharts can be generated for each value of a ClassificationVariable by assigning either the ColumnVariable or RowVariable role to that variable.

For example, when plotting the temperatures of different cities, a variable named City might be assigned to the Column role so that a separate plot is generated for each city. The assignment would resemble the following:

 
dataModel.setColumnVariable(new ClassificationVariable("City"));

If the Column role is assigned, plots are aligned horizontally by the variable's values. Each column has its own Category axis scale, and the plots share the same Response axis and also Response2 axis, when present.

If the Row role is assigned, plots are aligned vertically by the variable's values. Each row has its own Response axis scale and, if the Response2 role is used, Response2 axis scale. The plots share the same Category axis.

The Column and Row variable roles can both be assigned to the same graph. In that case, a separate line plot is produced for each unique pair of (column, row) values, and the plots are displayed in a grid.

Example
Multiple Plots in Columns: Swing-based code, Servlet-based code

LineChartTableDataModel: Valid Variable Roles

The following table summarizes the LineChartTableDataModel variable roles and the type of data each role supports.

Variable Role Class Type Numeric String Multiple Variables
CategoryVariable*
Assigns horizontal-axis variable
ClassificationVariable Yes Yes Yes
ResponseVariable*
Assigns left vertical-axis variable
AnalysisVariable Yes No Yes
Response2Variable
Assigns right vertical-axis variable
AnalysisVariable Yes No Yes
SubgroupVariable
Generates a separate plot for each value of the subgroup variable
ClassificationVariable No Yes No
CategorySortVariable
Determines the variable that will define the order in which the values are sorted along the category axis
Variable No Yes No
TopMarkerLabelVariable
Displays plot-point labels above markers
Variable Yes Yes No
BottomMarkerLabelVariable
Displays plot-point labels below markers
Variable Yes Yes No
ColumnVariable
Aligns multiple plots in columns
ClassificationVariable Yes Yes Yes
RowVariable
Aligns multiple plots in rows
ClassificationVariable Yes Yes Yes
* required variable

LineChartTableDataModel: Behavior

To generate a graph, a LineChart needs data columns for the CategoryVariable and ResponseVariable roles.

If the Response role is not assigned in the program code, a LineChart selects the first numeric column found in the LineChartTableDataModel and uses it as its Response variable. If there is no numeric column in the data, then it selects the first string column.

If the Category role is not assigned in the program code, a LineChart selects the first string column and uses it as the Category variable. If no valid string column is found, then it selects the first numeric column different from the Response and uses it as Category.

This default behavior occurs only when the Category and/or Response role is not assigned. If either role is assigned to a variable that does not exist in the data, the LineChart cannot display a graph.

LineChartTableDataModel: Events

A LineChartTableDataModel fires property change events when

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

LineChartTableDataModel: Error Handling

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

If the CategoryVariable and ResponseVariable roles are correctly assiged to existing variables but another role is incorrectly assigned, the LineChart displays a graph without the incorrect role. For example, if the CategoryVariable and ResponseVariable roles are correctly assigned but the ColumnVariable role is not, a graph using the Category and Response roles is generated, but the Column role is ignored.