Getting Bubble Chart Data Source Settings

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example displays an express report bubble chart, for which a legend is hidden. After starting the example the development environment console displays the following information:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Express Report section):

// Get bubble chart data view controller
MAExpressAnalysisReportViewController *contr = (MAExpressAnalysisReportViewController*)m_controller;
NSArray *controllers = [contr dataViewControllers];
MABubbleDataViewController *bubbleDataViewController;
for (int i = 0; i < controllers.count; i++){
    if([controllers[i] isKindOfClass:[MABubbleDataViewController class]]){
        bubbleDataViewController = controllers[i];
        // Display bubble chart
        [contr setDataViewMode:kViewModeBubble];
        // Get bubble chart data source
        BubbleDataViewDatasource *bubbleDataSource = bubbleDataViewController.bubbleDataSource;
        // Get bubble chart data source and display timeline value
        id<ChartDataSource> chartDataSource = bubbleDataViewController.dataSource;
        printf("Timeline value: %d\n", [chartDataSource currentTimestamp]);
        // Display name of file with bubble chart settings
        printf("Name of file with bubble chart settings: %s\n", [[bubbleDataViewController settingsPlistName] UTF8String]);
        // Display name and key of metric that determines bubble color
        if(bubbleDataSource.getColorMetricName != NULL) {
            printf("Name of metric that determines bubble color: %s\n", [[bubbleDataSource getColorMetricName] UTF8String]);
            printf("key of metric that determines bubble color: %lld\n", [bubbleDataSource colorMetricKey]);
        }
        // Display name and key of metric that determines bubble size
        if(bubbleDataSource.getSizeMetricName != NULL) {
            printf("Name of metric that determines bubble size: %s\n", [[bubbleDataSource getSizeMetricName] UTF8String]);
            printf("Key of metric that determines bubble size: %lld\n", [bubbleDataSource sizeMetricKey]);
        }
        // Display name and key of metric that determines X axis values
        if(bubbleDataSource.getXMetricName != NULL) {
            printf("Name of metric that determines X axis values: %s\n", [[bubbleDataSource getXMetricName] UTF8String]);
            printf("Key of metric that determines X axis values: %lld\n", [bubbleDataSource xMetricKey]);
        }
        // Display name and key of metric that determines Y axis values
        if(bubbleDataSource.getYMetricName != NULL) {
            printf("Name of metric that determines Y axis values: %s\n", [[bubbleDataSource getYMetricName] UTF8String]);
            printf("Key of metric that determines Y axis values: %lld\n", [bubbleDataSource yMetricKey]);
        }
        // Display number of bubble chart settings
        SNDictionary settings = [bubbleDataSource dumpSettings];
        printf("Number of bubble chart settings: %d\n", settings->count());
        // Display number of data series values for color, size, X and Y axes
        if(bubbleDataSource.hasColorData)
        printf("Number of data series values for color: %d\n", bubbleDataSource.colorValues.count);
        if(bubbleDataSource.hasSizeData)
        printf("Number of data series values for size: %d\n", bubbleDataSource.sizeValues.count);
        printf("Number of data series values for X axis: %d\n", bubbleDataSource.xValues.count);
        printf("Number of data series values for Y axis: %d\n", bubbleDataSource.yValues.count);
        // Get data series identifier and display its label
        NSString *seriesID = bubbleDataSource.seriesIDs[0];
        NSString *seriesTitle = [bubbleDataSource seriesTitleWithID:seriesID];
        printf("Data series label with the identifier %s: %s\n", [seriesID UTF8String], [seriesTitle UTF8String]);
        // Display data series value for color
        printf("%s %f\n", "Data series value for color", [[bubbleDataSource colorSeriesWithID: seriesID][0] doubleValue]);
        // Display data series value for size
        printf("%s %f\n", "Data series value for size", [[bubbleDataSource sizeSeriesWithID: seriesID][1] doubleValue]);
        // Display data series value for X axis
        printf("%s %f\n", "Data series value for X axis", [[bubbleDataSource xSeriesWithID: seriesID][2] doubleValue]);
        // Display data series value for Y axis
        printf("%s %f\n", "Data series value for Y axis", [[bubbleDataSource ySeriesWithID: seriesID][3] doubleValue]);
        // Display key of currently used metrics dimension and number of fixed dimensions
        printf("key of currently used metrics dimension: %lld\n", [bubbleDataSource currentMetricsDimensionKey]);
        printf("Number of fixed dimensions: %d \n", bubbleDataSource.fixedDimensions->count());
        // Display data source dimension names
        printf("Territory dimension name: %s\n", [bubbleDataSource observationDimension]->name()->UTF8String());
        printf("Observation object names: %s\n", [bubbleDataSource metricsDimension]->name()->UTF8String());
        printf("Calendar dimension name: %s\n", [bubbleDataSource timelineDimension]->name()->UTF8String());
        // Display timeline labels
        NSArray *timeAxisTitles = [bubbleDataSource timeAxisTitles];
        printf("Timeline labels: ");
        for (int i = 0; i < timeAxisTitles.count; i++) {
            printf("%s; ", [timeAxisTitles[i] UTF8String]);
        }
        // Display first element value of metrics dimensions names dictionary
        NSDictionary *dimKeys = [bubbleDataSource metricsDimensionsKeys];
        printf("\nFirst element value of metrics dimensions names dictionary: %s\n", [[[dimKeys allValues] objectAtIndex:0] UTF8String]);
        // Display first element value of metrics dimension elements names dictionary
        NSDictionary *elDimKeys = [bubbleDataSource metricsDimensionElementsKeys];
        printf("First element value of metrics dimension elements names dictionary: %s\n", [[[elDimKeys allValues] objectAtIndex:0] UTF8String]);
        return;
    }
}
NSLog(@"Bubble chart data view is not available");

It is also required to replace the code in the static example file MAExpressAnalysisReportViewControllerDelegateImpl.mm in the initWithOlapReport: method in the block:

if (self.isBubbleEnabled)

with the following code:

// Get report settings
SNDictionary bubbleOlapPlist = m_olapReport->storageDictionary()->objectForKey<NDictionary>(BUBBLE_OLAP_KEY);
// Create a report
SPPLOlapReport bubbleOlapReport = NULL;
if (bubbleOlapPlist != NULL) {
    bubbleOlapReport = PPLOlapReport::olapReport(m_olapReport->descriptor(), bubbleOlapPlist);
}
// Create a data table
m_bubblePivot = (bubbleOlapReport != NULL) ? PPLPivot::pivot(bubbleOlapReport) : PPLPivot::pivot(m_olapReport);
// Create a data source
m_bubbleDatasource = [[BubbleDataViewDatasource alloc] initWithPivot:m_bubblePivot];
// Create a metric selection controller
m_bubbleElementRoleSelector = [[MAElementDataSourceRoleSelectorViewController alloc] initWithBubbleDataSource:m_bubbleDatasource];
// Get bubble chart settings
SNDictionary bubbleSettings = m_olapReport->bubblesSettings();
// Get dimension element selection settings
SNDictionary selectionSetings = m_olapReport->selectionDictionary();
// Get bubble chart data source settings
SNDictionary bubbleDSSettings = m_olapReport->storageDictionary()->objectForKey<NDictionary>(BUBBLE_DS_KEY);
// Load settings
[m_bubbleDatasource loadSettings:bubbleSettings dataStorageSettings:bubbleDSSettings indicatorEmptySettings:selectionSetings];

And in the MAExpressAnalysisReportViewControllerFactory.mm file in the createReport: method in the block:

if (delegate.isBubbleEnabled)

with the following code:

// Create bubble chart data view controller
MABubbleDataViewController *controller = [[MABubbleDataViewController alloc] initWithDatasource:(BubbleDataViewDatasource *)delegate.bubbleDatasource];
// Set title visibility
controller.isDataViewTitleVisible = !!delegate.olapReport->title();
// Set controller delegate
controller.delegate = report;
// Set controller tag
controller.tag = kViewModeBubble;
// Set value for coefficient of correlation between bubble chart area size and its elements sizes, at which elements must be hidden
controller.contentOptimizationFactor = 1;
// Hide bubble chart elements that do not fit
controller.optimizeOn = YES;
// Enable zoom gesture
controller.zoomEnabled = YES;
// Set settings file name
controller.settingsPlistName = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"settings_ea_ipad.plist" : @"settings_ea_iphone.plist");
// Add controller to array of controllers
[controllers addObject:controller];
// Adds controller to pool of objects, for which links are automatically counted
[controller autorelease];

After executing the example the bubble chart with the hidden legend is displayed:

The browser console also displays values of bubble chart settings and its data source:

Timeline value: 0

Name of bubble chart settings file: settings_ea_ipad.plist

Name of metric that determines bubble color: GDP per capita, PPP (constant 2005 international $)

Key of metric that determines bubble color: 513

Name of metric that determines X axis values: GDP per capita, PPP (constant 2005 international $)

Key of metric that determines X axis values: 513

Name of metric that determines Y axis values: GDP per capita, PPP (constant 2005 international $)

Key of metric that determines Y axis values: 513

Number of bubble chart settings: 6

Number of data series values for color: 30

Number of data series values for size: 30

Number of data series value for X axis: 30

Number of data series values for Y axis: 30

Label for the series with the South Africa identifier: SAR

Data series value for color: 7974.707562

Data series value for size: 7732.457170

Data series value for X axis: 7410.955176

Data series value for Y axis: 7345.606990

Key of metric dimension used at the moment: 1557

Number of fixed dimensions: 0

Territory dimension name: Regions

Observation object names: Indicators

Calendar dimension name: Calendar

Timeline labels: 1990; 1991; 1992; 1993; 1994; 1995;

Value of the first element of metric dimension name dictionary: Indicators

Value of the first element of metric dimension element name dictionary: GDP per capita, PPP (constant 2005 international $)

See also:

Example of Component Use