## BarLineChart: Minimum Specification

The minimum specification for a BarLineChart requires a valid data model. Generally the data model should assign the Category variable role to a ClassificationVariable, and the LineResponse variable role to an AnalysisVariable. If the Category role is not assigned, the BarLineChart automatically assigns the Category role to the first string column found in the data model, or to the first numeric column if the model has no string column. If a BarResponse variable is not specified, the bars reflect the category variable’s frequency count. If a LineResponse variable is not specified, the BarLineChart does not generate a line overlay.

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

## BarLineChart: Functional Overview

The component can display bar charts in 2D or 3D view. It can use the values of a subgroup variable to divide each bar into segments, based on the value of the subgroup variable, and it can use the values of a classification variable to display a separate chart for each unique classification value.

For bar charts, each category of the Independent variable is displayed as a bar. If multiple response variables are specified for the chart, the bars from each response are displayed side-by-side for ease of comparison. For example, if response variables for actual and predicted sales are charted, the bars representing actual and predicted sales for each classification value are displayed side-by-side. If a subgroup variable is specified for the chart, the response values are first categorized by the subgroup variable's values, and then the bars are segmented to show the proportion each subgroup contributes to the statistic that is calculated for that classification value.

For line plots, if there are multiple response variables, the values for each response variable are represented by a separate plot line. If a subgroup variable is specified for the chart, the response values are first categorized by the subgroup variable's values, and then a separate plot line is generated to represent the statistic calculations for each subgroup. For multiple response variables or a subgroup variable, all plot lines use the same set of axes, and a different color and plot symbol is used for each displayed plot line.

The component can use the values of one or more classification variables to produce multiple charts. The charts can be arranged in columns (using the ColumnVariable role), rows (using the RowVariable role), or a graph matrix (using both roles). A separate chart is generated for each unique column or row value, or for each value pair when both a column and row variable are specified. You can control the arrangement and text of the labels and values that identify the column and row axes.

## BarLineChart: Data Access

A BarLineChart's data properties are defined in a data model that descends from BarLineChartDataModel, an abstract class whose subclasses provide a handle to the data and determine the number and arrangement of data elements (bars, plot points). BarLineChartDataModel has the following subclasses:

- BarLineChartTableDataModel models relational data from a Swing TableModel and maps the data columns to the graph.
- BarLineChartOLAPDataModel models OLAP data through a com.sas.storage.olap.OLAPDataSetInterface.

## BarLineChart: Output Formats

A BarLineChart's bar chart and line plot share the same response axis; thus, their response values must have the same output format. For example, if you assign a currency output format to the bar chart's response values, you must assign the same currency format to the line plot's response values:

    // Set an output format to response values for both the bar chart and the line plot
    dataModel.setBarResponseVariable(new AnalysisVariable("ActualSales", "dollar20.2"));
    dataModel.setLineResponseVariable(new AnalysisVariable("PredictedSales", "dollar20.2"));

If an output format is assigned to only one of the response variables, the output format is ignored.

## BarLineChart: Display Properties

A BarLineChart's individual display properties can be set by calling the BarLineChart's getGraphModel() method, which returns a BarLineChartModel that can be used to set the desired properties. The BarLineChartModel class contains

- BarLineChart-specific properties
- Common graph properties
- A collection of models that control the appearance of the graph's peripheral elements, such as its axes and legend.

Although modifying the BarLineChartModel provides considerable control, it can be tedious to modify properties individually. For example, graphs distinguish between different types of text, such as label text, value text, data-label text, and title text. The text might also apply to different locations, such as the response axis, response2 axis, category axis, and legend. Whereas the BarLineChartModel can independently control these different text types and locations, doing so requires you to apply the same properties to all applicable locations.

An easier way to set a BarLineChart's display properties is to apply a pre-defined GraphStyle to the chart. A graph style sets many of the graph's visual characteristics, such as its use of colors, fonts, background, transparency, drop shadows, and more. A graph style can be used as is or modified through the GraphStyle class.

A graph style can be specified as an argument on a BarLineChart's constructor. Or, it can be applied to an existing chart by calling the BarLineChart's applyGraphStyle() method as follows:

    BarLineChart barLineChart = new BarLineChart();
    barLineChart.applyGraphStyle(new GraphStyle(GraphStyle.STYLE_SCIENCE);

Applying a GraphStyle to a graph propagates the GraphStyle's properties onto all applicable graph properties, including those in the graph model.

Rather than use the style as is, you can modify it before applying it. Modifying the style definition is typically easier and more convenient than modifying the graph's individual display properties. For example, the GraphStyle class contains only a single set of value text propertes. After applying the modified style, you can still adjust individual properties through the graph model.

The following code fragment modifies a graph style before applying it to a graph, and then uses the graph model to adjust an individual property.

    // Create and modify a graph style
    GraphStyle graphStyle = new GraphStyle(GraphStyle.STYLE_SCIENCE);
       graphStyle.getValueTextStyle().setColor(Color.darkGray);
       graphStyle.getValueTextStyle().setFont(new java.awt.Font("Arial",Font.BOLD,14));

    // Apply the modified graph style to a chart
    BarLineChart barLineChart = new BarLineChart();
       barLineChart.applyGraphStyle(graphStyle);

    // Set the category axis value text to black
    BarLineChartModel graphModel=barLineChart.getGraphModel();
       graphModel.getCategoryAxisModel().getValueTextStyle().setColor(Color.black);

Whether you set a graph style or individual display properties, the new display settings override any previous settings that were applied to the graph. For example, if a gray background and yellow bar outlines have been set on a graph, and then a style is applied to that same graph, the style's background and outline settings replace the previously set gray background and yellow outlines.

## BarLineChart: Titles and Footnotes

The BarLineChart component supports four titles and two footnotes, each with its own display attributes. To display multiple lines of text with the same attributes, use the line-end character (\n) in the specified text string.

To assign a title or footnote,

- Create a NoteModel to encapsulate a text value with associated display attributes
- Assign the model to the chart by calling one of the BarLineChart's setTitle() or setFootnote() methods.

The easiest way to set the text for a title or footnote is to get the chart's title or footnote property and set its text as follows:

    barLineChart.getTitle1().setText("Line One\nLine Two");

To change the text attributes for a title or footnote, set the attributes on a NoteModel and assign the NoteModel to the appropriate title or footnote. The following example sets the title "Product Revenue" and displays it in blue, using a 24-point TimesRoman font with a drop shadow.

    NoteModel myTitle = new NoteModel( "Product Revenue" );
    myTitle.getTextStyle().setColor(Color.blue);
    myTitle.getTextStyle().setFont(new java.awt.Font("TimesRoman",Font.PLAIN,24));
    myTitle.getTextStyle().getShadowStyle().setVisible(true);

    // Create the graph and assign the title
    BarLineChart barLineChart = new BarLineChart();
    barLineChart.setTitle1( myTitle );

## BarLineChart: Usage Examples

The following example fragment graphs product revenue. It uses relational data from a Swing TableModel that contains a string column of Product IDs and a numeric column of product Revenues. To enhance the graph's appearance, the example assigns the "Magnify" GraphStyle to the chart.

    javax.swing.table.TableModel mySalesData = <...>;

    // Create the BarLineChart's data model.
    BarLineChartTableDataModel barLineChartDataModel = new BarLineChartTableDataModel( mySalesData );
    barLineChartDataModel.setCategoryVariable( new ClassificationVariable("Product") );
    barLineChartDataModel.setBarResponseVariable( new AnalysisVariable("Revenue") );
    barLineChartDataModel.setLineResponseVariable( new AnalysisVariable("Revenue") );

    // Create the BarLineChart applying the data model and the "Magnify" GraphStyle
    BarLineChart barLineChart = new BarLineChart( barLineChartDataModel,
      new GraphStyle(GraphStyle.STYLE_MAGNIFY) );
    barLineChart.getTitle1().setText("Product Revenue");
    barLineChart.getFootnote1().setText("Company Confidential");

Assuming the TableModel also contains a column named Year (numeric or string) that identifies the year, and a column named ProductType (numeric or string) that identifies the product type, the following example organizes the graph by year and product type:

    javax.swing.table.TableModel mySalesData = <...>;

    // Create the BarLineChart's data model.
    BarLineChartTableDataModel barLineChartDataModel = new BarLineChartTableDataModel( mySalesData );
    barLineChartDataModel.setColumnVariable( new ClassificationVariable("Year") );
    barLineChartDataModel.setRowVariable( new ClassificationVariable("ProductType") );
    barLineChartDataModel.setCategoryVariable( new ClassificationVariable("Product") );
    barLineChartDataModel.setBarResponseVariable( new AnalysisVariable("Revenue") );
    barLineChartDataModel.setLineResponseVariable( new AnalysisVariable("Revenue") );

    // Create the BarLineChart applying the data model and the "Magnify" GraphStyle
    BarLineChart barLineChart = new BarLineChart( barLineChartDataModel,
      new GraphStyle(GraphStyle.STYLE_MAGNIFY) );
    barLineChart.getTitle1().setText("Product Revenue");
    barLineChart.getTitle2().setText("By Year and Product Type");
    barLineChart.getFootnote1().setText("Company Confidential");

Assuming the TableModel also contains a numeric data column named PredictedRevenue, the following example compares predicted revenue to actual revenue by product organized by year and product type:

    javax.swing.table.TableModel mySalesData = <...>;

    // Create the BarLineChart's data model.
    BarLineChartTableDataModel barLineChartDataModel = new BarLineChartTableDataModel( mySalesData );
    barLineChartDataModel.setColumnVariable( new ClassificationVariable("Year") );
    barLineChartDataModel.setRowVariable( new ClassificationVariable("ProductType") );
    barLineChartDataModel.setCategoryVariable( new ClassificationVariable("Product") );
    barLineChartDataModel.setBarResponseVariable( new AnalysisVariableList(
       new String[] {"PredictedRevenue", "Revenue"} ) );

    // Create the BarLineChart applying the data model and the "Magnify" GraphStyle
    BarLineChart barLineChart = new BarLineChart( barLineChartDataModel,
      new GraphStyle(GraphStyle.STYLE_MAGNIFY) );
    barLineChart.getTitle1().setText("Predicted Revenue vs Actual Revenue");
    barLineChart.getTitle2().setText("By Year and Product Type");
    barLineChart.getFootnote1().setText("Company Confidential");

## BarLineChart: Behavior

The BarLineChart asynchronously updates when a PropertyChangeEvent is received from any of its models (DataModel, GraphModel or NoteModels).