Skip to content

Instantly share code, notes, and snippets.

View erikwett's full-sized avatar

Erik Wetterberg erikwett

View GitHub Profile
@erikwett
erikwett / visualization_create_label.js
Last active March 10, 2016 10:13
Create a chart and specify labels with Visualization API
View visualization_create_label.js
app.visualization.create( 'pivot-table',
[
"Year", //dimension
{"qDef" : { "qFieldDefs" : ["Case Owner Group"], "qFieldLabels" : ["Group"] }}, //dimension with label
{"qDef" : { "qDef" : "=Avg([Case Duration Time])", "qLabel" : "Avg Case Duration Time" }},//measure with label
{"qDef" : { "qDef" : "Sum( [Open Cases] )", "qLabel" : "Open Cases" }} //measure with label
],
{"title" : "Case Owner Group Case stats per year"}
).then( function ( visual ) {
visual.show( 'QV01' );
@erikwett
erikwett / visualization_create_top.js
Created March 10, 2016 10:29
Create chart with top values using Qlik Sense visualization API
View visualization_create_top.js
app.visualization.create( 'barchart',
[{
qDef: {qFieldDefs: ["Case Owner Group"]}, //dimension field
qOtherTotalSpec: {qOtherMode: "OTHER_COUNTED", qOtherCounted: "5"} //top 5 values
},
"=Avg([Case Duration Time])"], //measure
{"title": "On the fly chart"}
).then( function ( barchart ) {
barchart.show( 'QV01' );
} );
View mashup_show_in_tab
//add a new chart when the user clicks in the list of visualizations
vislist.delegate( 'a[data-id]', "click", function ( e ) {
var id = $( this ).data( 'id' );
addChart( app, id );
} );
// dynamically add a visualization to the tabs
function addChart ( app, id ) {
//create a tab container if it does not exist
if ( !tabContainer ) {
View mashup_get_visualization_data
//getObject returns a promise, so we use the then method to get the model
app.getObject( tabid, id, options ).then( function ( model ) {
//save the model for future use
tabContainer.visualizations[tabid] = model;
//the title will be in the model
tabContainer.setTitle( model, tabid );
//the Validated event will be triggered when there is new data
//use it to update the title
model.Validated.bind( function () {
tabContainer.setTitle( this, tabid );
View mashup_applyPatches
function reOrder ( vis, sortOrder, col ) {
// set the new column first in the new sortorder array
var newOrder = [col];
//append all other columns from the current sort order
sortOrder.forEach( function ( val ) {
if ( val !== newOrder[0] ) {
newOrder.push( val );
}
} );
var patches = [{
View mashup_get_selections.js
function FieldList ( app ) {
/*....*/
app.getList( 'CurrentSelections', function ( reply ) {
me.selections = reply.qSelectionObject.qSelections;
//render since selections have changed
me.render();
//use qBackCount and qForwardCount to enable/disable back and forward buttons
$( "[data-qcmd='back']" ).toggleClass( 'disabled', reply.qSelectionObject.qBackCount < 1 );
$( "[data-qcmd='forward']" ).toggleClass( 'disabled', reply.qSelectionObject.qForwardCount < 1 );
} );
View mashup_call_reload.js
//check if we are in personal mode(desktop) or not
var global = qlik.getGlobal( config ), isPersonalMode;
global.isPersonalMode( function ( reply ) {
isPersonalMode = reply.qReturn;
} );
/*..*/
if ( isPersonalMode ) {
app.doReload().then( function () {
app.doSave();
} );
View generic_object_prop_1.js
initialProperties : {
version: 1.0,
qHyperCubeDef : {
qDimensions : [],
qMeasures : [],
qInitialDataFetch : [{
qWidth : 2,
qHeight : 50
}]
}
View hypercube_property_panel.js
return {
type: "items",
component: "accordion",
items: {
dimensions: {
uses: "dimensions",
min: 1,
max: 1
},
measures: {
View mashup_create_cube.js
app.createCube( {
"qInitialDataFetch": [
{
"qHeight": 400,
"qWidth": 8
}
],
"qDimensions": [
{ "qDef": {"qFieldDefs": ["CaseNumber"]} },
{ "qDef": {"qFieldDefs": ["Status"]} },