Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to filter a chart using an API?

Hello.

I've got a following simple code:

var config = {

    host: "sense-demo.qlik.com",

    prefix: "/",

    port: 443,

    isSecure: true

}

require.config({

    baseUrl: (config.isSecure ? "https://" : "http://") + config.host + (config.port ? ":" + config.port : "") + config.prefix + "resources"

});

require(["js/qlik"], function (qlik) {

    qlik.setOnError(function (error) {

        alert(error.message);

    });

  

    var app = qlik.openApp("d972b07b-fd90-466c-97be-b7aeecca29ee", config);

    app.getObject($("#myDiv"), "cReWKcL");

   

    app.field("Team Name").selectMatch("Cubs", false); //Here I'm trying to display a chart only for the Cubs team

});

And it appears to be non-deterministic. Once I get a one bar (only for the Cubs) and after few reloads I get a chart for all of the teams. And the other way around.

Could you provide some help regarding how to apply filtering on charts using JS API?

Thanks in advance

Aleksander

1 Reply
Alexander_Thor
Employee
Employee

The methods are async so you can't rely on app.getObject to finish before you issue your selection.

Luckily all methods in the Capabilities API return a promise so you can establish some kind of flow control,

pseudo code:

app.getObject('mydiv', 'myobjectid').then(() => {

  app.field('myfield').selectMatch('Cubs', false)

})