Dynamic widget background image based on filter

Comments

6 comments

  • Avatar
    Jordy Finkers

    The widget script currenly is: 

    widget.on('render', function(sender,event){
    	
    	//	URL to the background Image
    	var imageLink = 'http://siliconangle.com/files/2014/12/BlackWhite-Logo.jpg'
    	
    	//	Set the chart background as the image
    	sender.queryResult.chart.plotBackgroundImage = imageLink;
    		
    })
    0
    Comment actions Permalink
  • Avatar
    Moti Granovsky

    Hi Jordy,

    If your widget filter is for an image name and not URL, you will need an additional step to load the URL from the EC. As it's not really part of the widget's data per se, that means running a parallel JAQL query to retrieve this URL.

    The way you would do this is:

    1. In the widget render event, retrieve the filters from the widget object, find the one (by dimension name) that contains your image name, and extract the selected value (from filter.members array)
    2. Run a custom JAQL query to the /jaql API endpoint to get the corresponding image URL, as a synchronous AJAX call (to block execution until you have the URL)
    3. When you get the response with the URL, assign the imageLink variable.

    I would say this isn't the most efficient way however - if for example the URL for each image follows a standard pattern, and thus the URL could be extrapolated from the image name, it would spare you the need to query the EC and make this much simpler and quicker. 

    0
    Comment actions Permalink
  • Avatar
    Jordy Finkers

    Thanks Moti.

     

    Would you have an example of step 2 - the JAQL query to run in the script?

    0
    Comment actions Permalink
  • Avatar
    Moti Granovsky

    Sure, I've recently published this tutorial to get you started with JAQL queries: https://developer.sisense.com/display/API2/JAQL+Tutorial

    0
    Comment actions Permalink
  • Avatar
    Jordy Finkers

    Thanks - Can that also be run as advanced filter?

    0
    Comment actions Permalink
  • Avatar
    Moti Granovsky

    Advanced filters are only a subset of JAQL - that view lets you write a custom JAQL-syntax filter for a chosen dimension. In this case, since you need to load a value from an entirely new dimension (which does not otherwise participate in your widget's query) advanced filters can't help, and a separate HTTP request is needed.

    0
    Comment actions Permalink

Please sign in to leave a comment.