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

Replacing the legend in a line chart with labels on each line


One of the problems with a standard QlikView line chart is that the legend is somewhat removed from the chart, and it can be difficult to keep going back and forth between the legend and the data to work out which line is which.

A way of resolving this is to remove the legend and replace it with labels on each line.

Getting ready

Load the following script:

CrossTable(Country, Sales)
LOAD * INLINE [
    Date, USA, UK, Japan, Germany
    2013-01-01, 123, 100, 80, 40
    2013-02-01, 134, 111, 75, 50
    2013-03-01, 155,  95, 70, 60
    2013-04-01, 165,  85, 88, 50
    2013-05-01, 154, 125, 90, 70
    2013-06-01, 133, 110, 75, 99
];

How to do it…

These steps will create a line chart with labels on each line instead of a legend:

  1. Add a new line chart. Add two dimensions, Date and Country.

  2. Add the following expression:

    Dual(
       If(Date=Max(total Date), Country, ''),
       Sum(Sales)
    )
  3. On the Expressions tab, ensure that the Values on Data Points option is checked.

  4. Click on Next until you get to the Presentation tab. Deselect the Show Legend option.

  5. Click on Finish on the wizard.

How it works…

The Dual function will only return a text value when the date matches the maximum date. Otherwise, it is blank. So, when we enable the Values on Data Points option, it only displays a value for the last data point.

It is critical that you don't set a number format for the expression. The Expression Default option means that it will use the text from the dual.

There's more…

Dual is a really useful function to allow us to define exactly what will be displayed on labels such as this. It is also really useful for sorting text values in a specific order.

See also

  • The Staggering labels in a pie chart recipe

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