Qlik Community

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Employee
Employee

Line charts tricks: In-Chart Legend

QlikView Standard Visualization objects have much more to offer than standard out of the box settings. This is why data centric apps developers love QlikView so much, because you can dig into every object properties expanding their usage case scenarios.

This is the case of the line chart; probably one of the oldest visualization methods available. It´s a pretty simple and straightforward way to represent data - often used to visualize a trend in data over intervals of time.


In-Chart Legend


This is a simple space saver trick; it will help you to replace QlikView standard legend with a customized in-chart legend.

Look at the chart below. It represent sales in two countries US and UK. As you can see, we don't have too much space to plot the chart and the legend. QlikView will automatically adjust the chart area to the real state in the object. In this case that will make my chart area to be really small.

1.png

One approach could be to move the legend to the bottom. This will make my chart area much bigger, specially true for long label scenarios. On the other side, by reducing the Y axis the lines look much flatter, and in some situations that could mean that some users wont perceive small variations in the chart.

2.png

Remember: To move or/and size chart components as legends, text in charts, and chart area, press the Shift and Ctrl keys and keep them depressed while a chart is active. You will enter the chart layout edit mode.

In edit mode, thin red rectangles will appear around those components of the chart that can be sized or moved. Use the mouse drag and drop technique to move things around.

What can we do to get the best of both worlds?

Another alternative could be something like the chart below, where legends appear right next to the each line.

3.png

To tune a line chart to look like the image above, you will need to follow the next steps:

    1. Create a standard line chart as in the picture.

    2. Use one expression per line, we cannot use this method when the lines are created based on dimensions.
      4.png
    3. Use Dual()

      Duplicate each expression and set the definition to

      if(Num= max(totalNum),dual('US',[United States of America]))

      Where, Num is the dimension name,'US' will be the text displayed in the chart and [United States of America] is the number I calculated with my first expression.

    4. To finish, remember to check Symbol and Values on Data Points for the expression.
      5.png

Pros:

  • This method will allow you to create mini sparkline using standard line charts.
  • The most obvious advantage will be to get more space for your chart area.
  • Due to in context information, in-Chart legend style will allow users to quickly consume the chart. Users doesn't need to apart their eyes from the chart to read the legend.

Cons:

  • Lack of dynamism: you have to create one expression per line displayed, rather than letting QlikView to include new elements as they came to the data model.
  • In situations where multiple lines have to be displayed this method may create confusion by overlapping the legends labels.
  • Hard-coding expression is required.

I will post a second part on this topic with another trick soon, stay tuned!

Enjoy Qliking!

AMZ

PS: if you have tricks you want to share with our Community left us a comment

34 Comments
Not applicable

Hi

Nice One..

You can also see the below link for Silent Legend.

http://community.qlik.com/docs/DOC-3753

Hope it may help.

922 Views
datanibbler
Esteemed Contributor

Hi,

good trick indeed!

Works well only for line_charts, though. Going with the standard built-in legend and just abbreviating ("US" and "UK" like you did anyway in the end) usually does the trick and you can just stick with the standard and just make the "legend rectangle" much smaller, expanding the chart_area.

That DUAL thing is cool, though.

0 Likes
922 Views
Employee
Employee

That's true, standard legend and abbreviated legend labels would be good.

0 Likes
922 Views
MVP
MVP

Good Post... Similar subject has been discussed in Developers COOKBOOK

0 Likes
922 Views
autopilot
Contributor III

Great post!

Will you elaborate on what you mean by "we cannot use this method when the lines are created based on dimensions."?

I was able to recreate your example except the value displayed at the end of the line is the number rather than the text.

0 Likes
922 Views
Not applicable

Another design trick is to use the title as a legend.  This method is best suited for only a small number of hard-coded categories, but can save space and look nice when used correctly.  This effect is achieved by utilizing the background color expression to match a text box title of the same color.

Example:

Example.JPG.jpg

922 Views
MVP & Luminary
MVP & Luminary

I think you can do your example without any additional expressions. Country as Dimension and a single Expression:

=Dual(

If(Num=Max(total Num), Country, ''),

Sum(Expression2)

)

Stephen Redmond covers this example well in his  book "Qlikview Cookbook for Developers".

-Rob

922 Views
autopilot
Contributor III

Nevermind......I figured it out. The expression's number format has to be set to "Expression Default".

Also - per Rob's comment - this is a link to a post where Stephen illustrates the same thing.

http://www.qliktips.com/2012/07/lose-legend-in-line-charts.html

0 Likes
922 Views
Employee
Employee

Good one Rebecca

0 Likes
922 Views
Employee
Employee

Hi Rob,

Thanks for the contribution! It's true that with just one expression you can have the in-chart legend. But you will need 2 expressions to create a mini sparkline chart as in the example. In some situations you may want a different color for the dot symbol and the line, then you will need additional expressions too.

0 Likes
922 Views
Employee
Employee

I see I mixed two ideas in my post. Just to make it clear, we don't need 2 expressions to have the label close to the line, just need to use dual(). To create a chart like in my example you still need 2 expressions.

The main benefit of having 2 expressions rather than just one is to be able to increase the data-density of your line chart by controlling last value color. This could help you to indicate change or variation vs previous period. It's basically a sparkline.

Sparkline - Wikipedia, the free encyclopedia

0 Likes
922 Views
Not applicable

Hi Rebecaa, your chart is nice.

0 Likes
922 Views
Partner
Partner

Hi Arturo,

I am still unable to figure out how the legend can be brought down the chart with single row. I already know that using Ctrl+Shift, we can move the legend. But even after moving the legend, I still get 6 rows of legends which I want to make into 1 or 2 rows. Can you help?

Cheers,

Naresh

0 Likes
922 Views
Employee
Employee

Naresh, you need to resize the legend rectangle and make it thinner.

0 Likes
922 Views
Partner
Partner

Hi Arturo,

Thanks for the response. Please observe the below screenshot. I have tried making the legend thinner but it is not adjusting itself into multiple columns but showing a scroll bar which an end user may not be interested. Am I missing anything else here?

Cheers,

Naresh

legend.jpg

0 Likes
922 Views
Not applicable

Hi Naresh

I try it work . in case still cannot , may be you should post your QVW file on forum , believe some one will help you up.

legend below 1 row.png

0 Likes
922 Views
Partner
Partner

Hi Paul,

Sadly, I am unable to attach the qvw here. It is showing options only to attach an image.

Cheers,

Naresh

0 Likes
922 Views
Employee
Employee

It all depends on how long your labels are, as in Paul's screenshot you can see short legends being displayed in one row. You could try to limit the legend length in Chart's properties window.

0 Likes
922 Views
Partner
Partner

Hey Arturo,

That worked like a charm once I limit the length of the legend.

Bit it would have been nice if QlikView itself decides the length and classify into the columns.

Thank You Very much.

Cheers,

Naresh

0 Likes
922 Views
Not applicable

Hey guys, 

I am given a task to calculate the frequency of calls across a territory. If the rep called a physician regarding the sale of the product 5 times, then frequency is 5 and HCP count is 1....I generated frequencies from 1 to 124 in my pivot table using a calculated dimension which is working fine. But my concern is :

My manager wants frequencies till 19 in order from 1..2..3..4...5..6.....19...

And from the frequency 21-124 as 20+.

I would be grateful if someone helps me with this.....Eager for the reply....

0 Likes
922 Views
Not applicable

good one

0 Likes
922 Views
Not applicable

Hi..

I am also facing the same issue.

need to display the legends only have data.

0 Likes
922 Views
Not applicable

Hi Arturo,

In the below chart, how would I change my Y-axis (Count) to Regions (AME, EMEA & APJ)

Regards,

Arun.

sample.jpg

0 Likes
922 Views
Not applicable

Hi Rebecca,

would you be so kind to explain me a little more in detail how you came to this very cool result?

Thanks in advance

best regards

Peter

0 Likes
922 Views
Not applicable

Hi Peter - send me your email address and I will send you a file that shows you what I did to create it.  I would upload it here, but it won't let me attach the file.

0 Likes
922 Views
Not applicable

Hi Rebecca,

My work email is email peter.kormos@tele2.com

Thanks for your efforts!

Bests

Peter

Beste Grüße / Best regards

Peter Kormos

Credit Risk and Fraud Analyst

Communication Services Tele2 GmbH

In der Steele 39

40599 Düsseldorf

phone +49 (0)211-74 004-659

fax +49 (0)211-74 004-906

email peter.kormos@tele2.com

www.tele2.de<http://www.tele2.de/>

Amtsgericht Düsseldorf - HRB 36232

Geschäftsführer - Oliver Rockstein, Niklas Sonkin

Diese E-Mail enthält möglicherweise vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige

Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese

Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this email

in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution

of the material in this e-mail is strictly forbidden.

0 Likes
922 Views
Not applicable

Hi Rebecca,

My work email is peter.kormos@tele2.com

Thanks for your efforts!

Bests

Peter

0 Likes
922 Views
Not applicable

Hi Rob,

Great contribution! I have checked that this expression requires that the number format is set to "Expression default". However, I would like that the axis are in % and it does not work with this number format. Is it possible to combine the dual expression and the axis in %?

Thanks,

Josep Ma

0 Likes
922 Views
MVP & Luminary
MVP & Luminary

I'm not sure without testing a specific example. Worst case, you can duplicate the expression as Arturo did in the original post.

-Rob

0 Likes
922 Views
Not applicable

Thanks! I'd like my dimension to be a temporal variable and it doesn't work. Any idea of how to solve it?

Thanks,

Josep Ma

0 Likes
922 Views