Send charts from qlik load script

Hello everyone, today with a little hack of the original post by Steve Dark (https://www.quickintelligence.co.uk/send-data-from-qlik-load-script/ ).

Basically the small tweak of the original function is the code for “&”

sub Encode(vEncodeMe, vEncoded)
let vEncoded = 
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(vEncodeMe
, ':', '%3a')
, '/', '%2f')
, '?', '%3f')
, '=', '%3d')
, '\', '%5c')
, '@', '%40')
, ' ', '+')
, '&', '%26') //added
;
end sub

Then, some example data

DATA:
Load 
	rowno() as id, 
    *
Inline [
Month, Value
Jan, 1
Feb, 10
Mar, 7
Apr, 8
May, 4
Jun, 20
Jul, 10
];

And the little secret sauce is https://image-charts.com/ , an online chart generator with the option of “GET” parameters. If you read the documentation, you will see there are a lot of options, but to keep this example simple we are going to generate a bar chart.

STR_DIM:
Load 
concat(Month,'|',id) as STR_DIM,
concat(Value,',',id) as STR_EXP
resident DATA;

//The "id" field is for sorting the data in the string, due to my regional configuration "Jan" has no numerical value

Let vDIM = Peek('STR_DIM', 0, 'STR_DIM');
Let vEXP = Peek('STR_EXP', 0, 'STR_DIM');

//Variables to create the axis

Set vBASE_URL = 'https://image-charts.com/chart?';

Let vCHART_TYPE = 'cht=bvg'; 
//bvg : BarChart Vertically Grouped
//bhg : BarChart Horizontally Grouped

Set vCHART_SIZE = 'chs=700x300';

Set vCHART_AXIS = 'chxt=x,y'; //Axis to show

Let vCHART_VALUES = 'chd=t:' & vEXP;

Let vCHART_LABELS = 'chxl=0:|' & vDIM; //Format <axis>:|<label1>|<label2>


Set vCHART_DATASERIES_LABEL = 'chdl=Visitors';

Let vCHART_URL = 
vBASE_URL & '&' & 
vCHART_TYPE & '&' & 
vCHART_SIZE & '&' & 
vCHART_LABELS & '&' &
vCHART_AXIS & '&' &
vCHART_VALUES & '&' &
vCHART_DATASERIES_LABEL
;

Then, the final step is embed the image in the HTML Body, to do this use the function Encode()

call Encode('<img src="$(vCHART_URL)" />', vMessage);

Also you can test the string in one of my favorites object  from Vizlib “Advance Text Object”, drawing the variable  vCHART_URL like this example

= '<img src="$(vCHART_URL)" />'

Result:

By the way, if you want to get rid of the watermark see the pricing!

Hope this little hack will help you.

See ya!

 

Hello world!

Welcome dear friend!

The main idea behind this blog will be to post useful info about topics like BI (particularly Qlik products), UX and things related.

Any feedback will be appreciated.

Let’s rock!