Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
QlikView for Developers Cookbook

You're reading from   QlikView for Developers Cookbook Take your QlikView training to the next level with this brilliant book that's packed with recipes which progress from intermediate to advanced. The step-by step-approach makes learning easy and enjoyable.

Arrow left icon
Product type Paperback
Published in Jun 2013
Publisher Packt
ISBN-13 9781782179733
Length 290 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Stephen Redmond Stephen Redmond
Author Profile Icon Stephen Redmond
Stephen Redmond
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

QlikView for Developers Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Charts 2. Layout FREE CHAPTER 3. Set Analysis 4. Advanced Aggregations 5. Advanced Coding 6. Data Modeling 7. Extensions 8. Useful Functions 9. Script 10. Improving Performance 11. Security Index

Creating custom pop-up labels on a bar chart


The default pop up for a QlikView bar chart is useful but is not always exactly what you want.

The format is as follows:

Dimension name = value

Expression label = value

Now, we may not like this pop up and wish to display the values differently or add different formats. We may even want to include additional information.

In the preceding example, the pop up shows the value of Sales $ for Germany. If I want to see the value of the Costs $, I need to hover over the Costs $ bar. And what if I wanted to see Margin $ or Margin %?

Getting ready

Create a new QlikView document and save it to a folder. Edit the script (Ctrl + E or the File menu – Edit Script).

Enter the following script:

LOAD * INLINE [
    Country, Sales, Costs
    USA, 1000, 800
    UK, 800, 700
    Germany, 900, 1000
    Japan, 600, 400
];

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

How to do it…

Use the following steps to create a new bar chart and add custom labels:

  1. Create a new bar chart with the following characteristics:

    Dimension

    Country

    Expression 1

    Sum(Sales)

    Expression 2

    Sum(Costs)

  2. Click on Finish.

  3. You should see a bar chart with two bars for each country. Confirm that the pop up on each bar displays as expected.

  4. Open the chart properties.

  5. Click on the Presentation tab and deselect the Pop-up Labels checkbox. Click on OK and note that there are no longer any pop-up labels appearing.

  6. Edit the properties again and click on the Expressions tab. Click on the Add… button and enter the following expression:

    ='Sales : ' & Num(Sum(Sales), '#,##0')
  7. Click on OK.

  8. Deselect the Bar option for this expression and turn on the Text as Pop-up option. Click on OK.

    Note

    Note that the new custom pop up is now active and displays the sales value whether you hover over the Sales $ or Costs $ bar.

  9. Edit the properties again and edit the pop-up expression as follows:

    = Country & chr(10)  
    & 'Sales : ' & Num(Sum(Sales), '$(MoneyFormat)') & chr(10)
    & 'Costs : ' & Num(Sum(Costs), '$(MoneyFormat)') & chr(10)
    & 'Margin : ' & Num(Sum(Sales)-Sum(Costs), '$(MoneyFormat)') 
    & chr(10) & 'Margin % : ' 
    & Num(1-(Sum(Costs)/Sum(Sales)), '0.0%')
  10. Click on OK on the expression editor and then click on OK to close the properties.

  11. Check that the custom pop up is displayed.

How it works…

By turning off the Bar option for the expression, QlikView will not try and evaluate the expression as a value and will not try to render a bar for it. By turning on the Text as Pop-up option, we tell QlikView to calculate the text of the expression and display it in the pop up.

We also had to turn off the default pop-up option in the Presentation tab or else it would display both (which might be what you want, have a play with it).

The chr function is useful to know about adding, so called, non-printable characters into your output. chr(10) is a line feed that moves the text onto the next line.

Note

Note that we have used a variable here for the format string. MoneyFormat is one of the standard QlikView variables that are generated in the script when you first open the script editor.

There's more…

The cool thing about this is that you can use it everywhere! It works in a lot of different charts and is a great way of giving users additional information about the data that they are looking at.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image