Tutorial: Creating a Line Chart Query

Creating a Line Chart Query



This tutorial explains how to use the sap.bc.ina.api.impl.inav2.LineChartQuery class and its result.

First declare your sina variable and define the right dataSource object. To define SAP HANA analytical or attribute views as data source, you need the package name and the object name.

Declaration and definition of sina and data source

var sina = sap.bc.ina.api.sina;
var dataSource = {
    "packageName" : "sap.bc.ina.demos.epm.views",
    "objectName"  : "V_EPM_PRODUCT"
};

In the next step, create the query. In this example, you call the method with the data source property, set the dimensions and add the measureY property.

Creating the query

var query = sina.createLineChartQuery({
    dataSource : dataSource,
    dimensionX : "CURRENCY_CODE",
    dimensionLine : "PRODUCT_ID",
    measureY   : {name: "PRICE", aggregationFunction: "COUNT"}
});

When the query was sent, you get back a result set. The first parameter of the method is the callback function on success. If everything went right, you get one object with your all your results. If not, the second parameter is the callback function on error.

query.getResultSet(function (resSet){
    // --- do something on success
    console.log(resSet);
}, function (jqxhr){
    // --- do something on error
    console.log(jqxhr);
});

The result object looks like this:

resSet = {
    properties : {},
    elements : [
        0 : {
            label : "AD-1000",
            value : [
                0 : {
                    x : "CAD",
                    y : 1
                }
            ]
        },
        1 : {
            label : "AD-1063",
            value : [
                0 : {
                    x : "CAD",
                    y : 1
                }
            ]
        }
    ]
}

Complete example

<html>
    <head>   
        <meta charset="utf-8">
        <title>Simple Information Access</title>
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>  
        <script src="/sap/bc/ina/api/sina/release/sap.bc.ina.api.sina.min.js" type="text/javascript"></script>
        <script>
            var sina = sap.bc.ina.api.sina;
            var dataSource = {
                "packageName" : "sap.bc.ina.demos.epm.views",
                "objectName"  : "V_EPM_PRODUCT"
            };
            var query = sina.createLineChartQuery({
                dataSource : dataSource,
                dimensionX : "CURRENCY_CODE",
                dimensionLine : "PRODUCT_ID",
                measureY   : {name: "PRICE", aggregationFunction: "COUNT"}
            });
            query.getResultSet(function (rs){
                console.log(rs);
            }, function (jqxhr){
                console.log(jqxhr);
            });
        </script>
    </head>
    <body>
        <!-- do something -->
    </body>
</html>