Skip to main content Skip to complementary content

Angular chart

The Angular chart example demonstrates a simple chart with basic AngularJS rendering.

Finding the examples

  • Qlik Sense Desktop: ...\Users\<UserName>\Documents\Qlik\Examples\Extensions.

  • Qlik Sense: ...\ProgramData\Qlik\Examples\Extensions.

Full code example

Example breakdown

  1. Edit the applicable fields of the QEXT file to set a default title, description, icon and type.

  2. Define properties and load reference to the html file where we code the AngularJS rendering:

    define(["jquery", "text!extensions/com-qliktech-angularchart/template.html"], function($, template) {'use strict';
    
  3. Inject the template HTML file "text!extensions/com-qliktech-angularchart/template.html"

    	return {
    		template : template,
  4. Define a cube by setting up the initial properties to include a qHyperCubeDef.

    		initialProperties : {
    			version : 1.0,
    			qHyperCubeDef : {
    				qDimensions : [],
    				qMeasures : [],
    				qInitialDataFetch : [{
    					qWidth : 2,
    					qHeight : 50
    				}]
    			}
    		},
  5. Define the Properties panel to include sorting and the number of dimensions and measures.

    		definition : {
    			type : "items",
    			component : "accordion",
    			items : {
    				dimensions : {
    					uses : "dimensions",
    					min : 1,
    					max : 1
    				},
    				measures : {
    					uses : "measures",
    					min : 1,
    					max : 1
    				},
    				sorting : {
    					uses : "sorting"
    				},
    				settings : {
    					uses : "settings"
    				}
    			}
    		},
  6. Enable snapshots.

    		snapshot : {
    			canTakeSnapshot : true
    		},
  7. Create a function in the controller that dynamically calculates the width of the bar.

    		controller : ['$scope',
    		function($scope) {
    			$scope.getWidth = function(row, measureinfo) {
    				var width = 80 * row[1].qNum / ( measureinfo ? measureinfo[0].qMax * 1.5 : 1) + '%';
    				return {
    					"width" : width
    				}
    			}
    		}]
  8. In the template.html file, use ng-repeat to iterate all the data and ng-style to apply the correct width defined in the controller as getWidth().

    <div qv-extension style="height: 100%; position: relative; overflow: auto;" >
    	AngularJS example extension
    	<div style="height: 100%; position: relative;">
    		<div ng-repeat="row in layout.qHyperCube.qDataPages[0].qMatrix">
    			<div title ='{{row[0].qText}}: {{row[1].qText}}'>
    				<div style='width:15%;height:32px;float:left;font-family:Arial;font-size:12px;line-height:32px;clear:both;overflow:hidden'>{{((row[0].qIsOtherCell)?layout.qHyperCube.qDimensionInfo[0].othersLabel:row[0].qText)}}</div>
    				<div ng-style='getWidth(row, layout.qHyperCube.qMeasureInfo )' style='height:32px;float:left;display:block;background-image : url("/extensions/com-qliktech-angularchart/qlogo.jpg");'>&nbsp;</div>
    				<div style='clear:both'></div>
    				</div>
    		</div>
    	</div>
    </div>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!