Skip to main content

Axis Binding

Axis binding retrieves the currently marked value in a column as base for an axis expression. It is used to set up visualizations with axis expressions changing in response to marking in other visualizations.

Overview

In the user interface the axis binding feature is referred to as Column from Marked. It is accessed from the context menu of the axis selectors. To get acquainted with it, run the Data Relationships tool, which is similar to the example described here.
The purpose of the following example is to explain how to set up axis binding via the API.

Example

The sample uses two data tables. One holds sales data, and starts as follows:

Year Month Category Type Sales Cost
2004 January Fruit Apples 17 14
2004 January Fruit Pears 26 17
2004 January Fruit Bananas 31 28
2004 January Vegetables Cucumber 13 9
2004 January Vegetables Tomatoes 18 14
2004 January Vegetables Lettuce 28 26
2004 February Fruit Apples 17 12
2004 February Fruit Pears 27 18
2004 February Fruit Bananas 35 29
2004 February Vegetables Cucumber 13 9
2004 February Vegetables Tomatoes 15 15
2004 February Vegetables Lettuce 26 26
2004 March Fruit Apples 14 13
2004 March Fruit Pears 24 17
2004 March Fruit Bananas 36 29
2004 March Vegetables Cucumber 12 10

The columns of the second table contains the names of columns in the first table:

Configuration X Y
Category vs. Sales Category Sales
Category vs. Cost Category Cost
Type vs. Sales Type Sales
Type vs. Cost Type Cost

Goal

The goal is to create a table visualization that controls the axis in a bar chart:

  • The table visualization shows the second data table.
  • When the user marks a row in the table, the bar chart is configured by the values in the X and Y columns.

When the user selects the row Category vs. Cost, the bar chart is configured to show the sum of Cost for each category. In the user interface it will look like this:

Bar chart

Code Example

The goal is accomplished by a single method. It is assumed that the first table has been opened and is the default data table. The hypothetical AddConfigurationDataTable method is used to load the second table.

public void CreateTableAndBarChartWithAxisBinding(AnalysisApplication application)
{
    // Add the data table used for defining axis bindings.
    DataTable configurationTable = AddConfigurationDataTable();

    // Create a table visualization
    TablePlot tablePlot = 
        application.Document.ActivePageReference.Visuals.AddNew<TablePlot>();
    tablePlot.Title = "Configurations";

    // Connect the table to data
    tablePlot.Data.DataTableReference = configurationTable;

    // Set filtering for the visualization
    tablePlot.Data.UseActiveFiltering = true;

    // Set marking for the visualization
    DataManager dataManager = application.Document.Data;
    DataMarkingSelection marking = 
        dataManager.Markings.DefaultMarkingReference;
    tablePlot.Data.MarkingReference = marking;

    // Add columns to the table
    tablePlot.Columns.AddRange(new string[]
    {
        "Configuration",
        "X",
        "Y"
    });

    // Create a bar chart whose X and Y axes will be contolled by the marking
    // in the table.
    BarChart barChart = 
        application.Document.ActivePageReference.Visuals.AddNew<BarChart>();
    barChart.Data.DataTableReference =
        dataManager.Tables.DefaultTableReference;
            
    // Setup the x axis to show the column defined by
    // the values in column X.
    AxisBinding xBinding = new AxisBinding();
    xBinding.ColumnReference = configurationTable.Columns["X"];
    xBinding.ExpressionTemplate = "<{0}>";
    xBinding.MarkingReference = marking; 
    barChart.XAxis.Binding = xBinding;

    // Setup the y axis to show the column defined by
    // the values in column Y.
    AxisBinding yBinding = new AxisBinding();
    yBinding.ColumnReference = configurationTable.Columns["Y"];
    yBinding.ExpressionTemplate = "Sum({0})";
    yBinding.MarkingReference = marking;
    barChart.YAxis.Binding = yBinding;
}