The variables that are used in any graph perform logical roles in that graph. For example, one variable typically serves as the role of independent or category variable, and another typically serves as the role of dependent or response variable. These and other logical roles are common to many types of graphs, and numerous variables in the data might be suitable for performing them.
Logical roles are not stored as part of the data. Rather, they represent the way that a chart will use the data, and the API for each chart type provides a table-data model that is used to assign variable roles. For example, the BarChartTableDataModel is used to assign variable roles for a bar chart, and the LinePlotTableDataModel is used to assign variable roles for a line plot.
To assign variable roles you
Typically you would set the Category and Response roles, and then use other roles as needed.
The following code creates a bar chart and uses the Category role in the chart:
// Create a Swing TableModel javax.swing.table.TableModel mySalesData = <...>; // Create the BarChart's data model BarChartTableDataModel barChartDataModel=new BarChartTableDataModel(); barChartDataModel.setModel(mySalesData); // Assign the Category and Response variable roles to data variables. // This assumes that data variables named Product and Revenue are in the data. barChartDataModel.setCategoryVariable(new ClassificationVariable("Product")); barChartDataModel.setResponseVariable(new AnalysisVariable("Revenue")); // Create the BarChart and apply the data model to it BarChart barChart=new BarChart(); barChart.setDataModel(barChartDataModel);
The code above produces a bar chart that shows product revenues. If the data contain an Expense variable, you could change the graph so that it displays product expenses by reassigning the Response role to the Expense variable.
Constructing charts by using variable roles enables you to assign characteristics to a role rather than to a variable. That way, any variable that assumes the role has the characteristics applied to it during its tenure in the role. For example, you might assign a sort order to the Category role, and a statistic to the Response role. The values for any variables that are assigned the Category role will be sorted in the assigned sort order, and the graph will display the requested statistic, based on the values of any variable that is assigned the Response role. This use of logical roles provides continuity to your data display when generating multiple graphs in an application.
The following table shows some of the common roles that are available in most of the components. The table is not meant to be comprehensive; rather, it provides a general idea of the types of roles that variables typically play in a graph.
|Common Roles||General Description|
|Category||Main variable used to group data values together; usually in the direction of width|
|Color||Grouping variable using color to distinguish among data values|
|Column||Variable that identifies in the attached TableModel the data column(s) whose values are used to horizontally group the charts|
|Group||Higher level variable used to group category values together|
|Response||Numeric variable showing the result of applying a statistic to a category|
|Row||Variable that identifies in the attached TableModel the data row(s) whose values are used to vertically group the charts|
|Subgroup||Variables used to show contributions of certain data values to a category|