Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Displaying long labels on chart X-axis

Someone asked this question http://community.qlik.com/message/209386#209386 on the recent "Ask the Experts - Visualization" event. It was an intriguing question because I've run up against this problem before.  The orginal thread is locked, so I thought I would post a solution here. The orginal question was:

Hi Experts,

What is the best way of showing long values on x-axis for charts since qlikview can't do wrap text on values?

Most of the time, the best we could show our client is to make it at 45 degrees angle or make the dimension on y-axis, horizontal chart. It doesn't look nice.

This is not very qool... don't you think?

Any suggestions? Thanks!

There appears to be no way to get the wrap to look noce in the UI. So my solution is to use a script SUB  to create a new field that's broken into segments based on the first space after a minmum segment length. And then use the new field as the chart. It may look a bit daunting, but the only thing you need to modify the CALL statement at the end.

SUB SplitString (vField, vTable, vSegLen, vSplitField)

Split_temp:

LOAD *,

          trim(mid($(vField), Start, Count-1)) as Split,

          RowNo() as SplitId

;

LOAD *,

          index( mid($(vField) & ' ', Start+$(vSegLen)), ' ' )+$(vSegLen)  as Count

;

LOAD

          $(vField),

          if($(vField) = Previous($(vField))

                    ,peek('Start')+peek('Count')

                    ,1

          )as Start

RESIDENT $(vTable)

WHILE IterNo() <= div(len($(vField)),$(vSegLen))+1

;

LEFT JOIN($(vTable))

LOAD

          $(vField),

          concat(Split, chr(10), SplitId) as $(vSplitField)

RESIDENT Split_temp

WHERE len(trim(Split)) > 0

GROUP BY Title

;

DROP TABLE Split_temp;

END SUB

MyTable:

LOAD *, RecNo() as RecId INLINE [

Title

This is a long title that spans a long ways

This is a long title that spans a long ways

This one is even very much longer then the previous long title

A shorter title

The rain in Spain

Healthcare / Services / Consulting / Accounting

]

;

// Call parms are Field, Tablename, SplitLength, OutputSplitField

// Split the string in "Field" at the first blank after segment length of "SplitLength".

// New field "OutputSplitField" will be joined to table "Tablename"

CALL SplitString('Title', 'MyTable', 15, 'SplitTitle');

-Rob

http://robwunderlich.com

13 Replies
cbushey1
Creator III
Creator III

I realized that if the field you are grouping by and the vFieldName are the same field, when you try to load them into the first load statement of the Split_temp it will error. To get around this, I simply rename this field in the load and as a result rename it in the Group by clause.

So the final code should be this( bolded the two edits):

SUB SplitString (vField, vTable, vSegLen, vSplitField,vGroupByField)

Split_temp:

LOAD *,

          trim(mid($(vField), Start, Count-1)) as Split,

          RowNo() as SplitId

;

LOAD *,

          index( mid($(vField) & ' ', Start+$(vSegLen)), ' ' )+$(vSegLen)  as Count

;

LOAD

          $(vField),

         $(vGroupByField) as GroupByField,

          if($(vField) = Previous($(vField))

                    ,peek('Start')+peek('Count')

                    ,1

          )as Start

RESIDENT $(vTable)

WHILE IterNo() <= div(len($(vField)),$(vSegLen))+1

;

LEFT JOIN($(vTable))

LOAD

          $(vField),

          concat(Split, chr(10), SplitId) as $(vSplitField)

RESIDENT Split_temp

WHERE len(trim(Split)) > 0

GROUP BY GroupByField,$(vField)

;

DROP TABLE Split_temp;

END SUB

paulwalker
Creator III
Creator III

HI ROb,

This code working perfectly..but its repeating the dimension text..

10.JPG

Please could you give suggestion

joanna22
Contributor
Contributor

hi Rob, 

When I try it in qlik sense.    The title is broken to two or three lines in table, but it still showed one line in the Bar chart both vertical and horizontal. 

ilyagolev
Contributor
Contributor

Yes, the same situation, in Qlik Sense I can't find a way how to show a dimension's title in two or more rows.