This tutorial explains how to use the sap.bc.ina.api.impl.inav2.GroupBarChartQuery 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.
var sina = sap.bc.ina.api.sina;
var dataSource = {
"packageName" : "sapphire",
"objectName" : "LIQUID_SALES_AV1"
};
In the next step, create the query. In this example, you call the method only with the data source property. All other properties can be defined later.
var query = sina.createGroupBarChartQuery({
dataSource : dataSource
});
Now you add the dimensions, filter conditions, and measures to the query. The methods return the query object (this
), so the methods can be chained. The sequence in which you add dimensions to the query determines the nesting of the dimensions in the result set.
query.addDimension({name: "COMPANY_NAME", sortOrder: 1, top: 5}).addDimension("YEAR", 1, 4);
query.addFilterCondition("YEAR", "=", "2011").addFilterCondition("YEAR", "<", "2010");
query.addMeasure({name:"NET_AMOUNT", aggregationFunction:"SUM"});
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 : [
{
label : "Colorado",
value : [
{
label : "2009",
value : [
{
label : "NET_AMOUNT",
value : {
value : "60.457,30",
valueRaw : 60457.3
}
}
]
},
{
label : "2011",
value : [
{
label : "NET_AMOUNT",
value : {
value : "34.277,95",
valueRaw : 34277.95
}
}
]
}
]
}
]
}
<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" : "sapphire",
"objectName" : "LIQUID_SALES_AV1"
};
var query = sina.createGroupBarChartQuery({
dataSource : dataSource
});
query.addDimension("COMPANY_NAME").addDimension("YEAR", 1, 4);
query.addFilterCondition("YEAR", "=", "2011").addFilterCondition("YEAR", "<", "2010");
query.addMeasure({name:"NET_AMOUNT", aggregationFunction:"SUM"});
query.getResultSet(function (resSet){
// --- do something
console.log(resSet);
}, function (jqxhr){
// --- do something
console.log(jqxhr);
});
</script>
</head>
<body>
<!-- do something -->
</body>
</html>