Book Image

QlikView for Developers Cookbook

By : Stephen Redmond
Book Image

QlikView for Developers Cookbook

By: Stephen Redmond

Overview of this book

QlikView has been around since 1993, but has only really taken off in recent years as a leader in the in-memory BI space and, more recently, in the data discovery area. QlikView features the ability to consolidate relevant data from multiple sources into a single application, as well as an associative data model to allow you to explore the data to a way your brain works, state-of-the-art visualizations, dashboard, analysis and reports, and mobile data access. QlikView for Developers Cookbook builds on your initial training and experiences with QlikView to help you become a better developer. This book features plenty of hands-on examples of many challenging functions. Assuming a basic understanding of QlikView development, this book provides a range of step-by-step exercises to teach you different subjects to help build your QlikView developer expertise. From advanced charting and layout to set analysis; from advanced aggregations through to scripting, performance, and security, this book will cover all the areas that you need to know about. The recipes in this book will give you a lot of the information that you need to become an excellent QlikView developer.
Table of Contents (19 chapters)
QlikView for Developers Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Staggering labels in a pie chart


I am not a big fan of using pie charts for many segments. The more segments that there are, the less easy it is to see the data. As the segments get smaller, even the labels get smudged into each other.

If you absolutely, positively must create this type of chart, you need to have a better strategy for the labels.

Getting ready

Load the following script:

LOAD * INLINE [
    Country, Sales
    USA, 100000
    Canada, 50000
    Mexico, 25000
    UK, 70000
    Germany, 20000
    Brazil, 15000
    France, 10000
    Japan, 9000
    China, 8000
    Australia, 7000
    South Korea, 5000
    New Zealand, 4000
    Italy, 2000
];

How to do it…

Follow these steps to create a pie chart with staggered labels:

  1. Create a new pie chart.

  2. Add Country as the dimension.

  3. On the Expressions tab, add the following expression:

    Dual(
      Country & '-' & 
      Num(sum(Sales), '#,##0') & 
      Repeat(chr(13)&chr(10), rank(Sum(Sales))-6), 
      sum(Sales)
    )
  4. Select the Values on Data Points option.

  5. On the Sort tab, select the Y-Value option. Confirm Descending as the direction.

  6. On the Presentation tab, deselect the Show Legend option.

  7. Click on Finish.

  8. Resize the chart so that all the values can be seen.

How it works…

The magic here is the Repeat function:

Repeat(chr(13)&chr(10), rank(Sum(Sales))-6)

The ASCII characters 13 and 10 give us a carriage return and line feed. Note that there is a Rank()-6 here. Basically, the repeat doesn't kick in until you get to the seventh ranked value in the dimension. There is no reason to start staggering for the earlier values.

There's more…

This is the only time that I have actually had to use the Repeat function in a chart. It does have uses in the frontend in Text objects. Mostly, it would be used in the script to generate data.