Creating HyperCubes

The in-memory associative Qlik Engine is speedy and powerful when it comes to aggregating and calculating data on the fly. As such, it sometimes makes sense to leverage the Qlik Engine to calculate a dataset which you then process for a purpose other than visualizations. Alternatively, you could also build amazing, highly complex visualizations and utilize multiple HyperCubes to calculate the necessary data for them. HyperCubes are created using the qlik.app.createCube(qHyperCubeDef, callback) method. It's important to correctly define the qHyperCubeDef object before creating the cube, something which is explained in detail in Chapter 13, Creating Extensions in Qlik Sense.

The following example will create a HyperCube with the same dimensions as the ones in the example of creating visualizations on the fly, and will output the result to the HTML page as a list instead of visualizing it as a bar chart:

<html> 
<head>
<link href="https://<qlik_sense_servername>/resources/autogenerated/qlik-styles.css" rel="stylesheet">
<script src="https://<qlik_sense_servername>/resources/assets/external/requirejs/require.js"></script>
<script>
var config = {
host: 'localhost',
prefix: '/',
port: 443,
isSecure: true
};

require.config({
baseUrl: ( config.isSecure? "https://" : "http://" ) + config.host + (config.port? ":" + config.port: "") + config.prefix + "resources"
});

require(["js/qlik"], function ( qlik ){
qlik.setOnError(function(error) {
alert(error.message);
});

var app = qlik.openApp('Mastering QS.qvf');
app.createCube({
qDimensions:[ {
qDef:{
qFieldDefs : ["
Case Owner Group"]
}
}
}],
qMeasures:[{
qDef:{
qDef : "
=Avg([Case Duration Time])"
}
}],
qInitialDataFetch:[{
qTop: 0,
qLeft: 0,
qHeight: 20,
qWidth: 3
}]
}, function(reply) {
var str = "";
$.each(reply.qHyperCube.qDataPages[0].qMatrix, function(key, value) {
str += '<li>' + value[0].qText + ':' + value[1].qText + '</li>';
});
$('#list').html(str);
});
})

</script>
</head>
<body>
<ul class="qlik-list" id="list"></ul>
</body>
</html>

While the definition of the HyperCube and the coding of it might look cumbersome, the performance is instantaneous and, as such, creating HyperCubes in web apps or mashups can become a very powerful tool to calculate complex aggregations over a large amount of data in the backend with seamless integration, using the API to then render or process the results in the frontend.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.17