UpdateD3UsingBQL JavaScript

<html>
<body>
  <div id="wordCloud"></div>
  <script src="https://mrc.bws.birst.com/js/birst_embed.js"></script>
  <script type="text/javascript" src="//d3js.org/d3.v3.js"></script>
  <script type="text/javascript" src="https://www.jasondavies.com/wordcloud/cloud.min.js"></script>
  <script type="text/javascript">
    var eventHandler=function(e){

      //this is to escape single quote in the param name
      function escapeParam(str) {
        str = str.replace(/'/g, "\\'")
        return str
      }
      var shouldResetQuery=false;
      if(e.data.operation==="setFilters"){
    //This is for generating query from the set filter data for ProductName
    var qu="SELECT TOP 100 USING OUTER JOIN [BirthDate: Sum: Quantity] 'COL0' , [Products.ProductName] 'COL1'  FROM [ALL] WHERE ((";  
      for(var i=0;i<e.data.filters.length;i++){
        var obj=e.data.filters[i];
        if(obj.key==="Products.ProductName"){
          var valArr=String(obj.value).split(",");
          shouldResetQuery=(valArr.length && obj.value)?false:true;
          for(var q=0;q<valArr.length;q++){
            if(q===valArr.length-1){
              qu+="[Products.ProductName]='"+escapeParam(valArr[q])+"'";
            }else{
              qu+="[Products.ProductName]='"+escapeParam(valArr[q])+"' OR ";
            }
          }
          qu+="))";
          if(shouldResetQuery){
            qu="SELECT TOP 100 USING OUTER JOIN [BirthDate: Sum: Quantity] 'COL0' , [Products.ProductName] 'COL1'  FROM [ALL]"
          }
          BirstConfig.getData(qu);
          }
        }
      }

if(e.data.operation==="executeQueryResult"){
    var glbWidth = window.innerWidth; // Width of tagcloud in pixels
    var glbHeight = window.innerHeight; // Height of tagcloud in pixels
    var dataList=[];
    for(var i=0,len= e.data.result.rows.length;i<len;i++){
      var sub= e.data.result.rows[i];
      var obj={size:(sub[0]/40),text:sub[1]};
      dataList.push(obj);
    }
    d3.select("#wordCloud").selectAll("*").remove();
    //D3
    var color = d3.scale.linear()
    var fill = d3.scale.category20();
    var draw = function( words ) {
      d3.select( '#wordCloud' ).append( 'svg' )
      .attr( 'width', glbWidth )
      .attr( 'height', glbHeight )
      .append( 'g' )
      .attr( 'transform', 'translate(' + glbWidth / 2 + ',' + glbHeight / 2 + ')' )
      .selectAll( 'text' )
      .data( words )
      .enter().append( 'text' )
      .style( 'font-size', function ( d ) {
        return d.size + 'px';
      } )
      .style( 'font-family', 'Impact' )
      .style( 'fill', function ( d, i ) {
        return fill( i );
      } )
      .attr( 'text-anchor', 'middle' )
      .attr( 'transform', function ( d ) {
        return 'translate(' + [d.x, d.y] + ')rotate(' + d.rotate + ')';
      } )
      .text( function ( d ) {
        return d.text;
      } )
      .on( 'click', function ( d ) {
        alert( d.text );
      } );
    }
    d3.layout.cloud().size( [glbWidth, glbHeight] )
    .words( dataList )
    .padding( 5 )
    .rotate( function () {
      return ~~(Math.random() * 2) * 90;
    } )
    .font( 'Impact' )
    .fontSize( function ( d ) {
      return d.size;
    } )
    .on( 'end', draw )
    .start();
  }
}
BirstConfig.callBack(eventHandler)
BirstConfig.getData("SELECT TOP 100 USING OUTER JOIN [BirthDate: Sum: Quantity] 'COL0' , [Products.ProductName] 'COL1'  FROM [ALL]");
</script>
</body>
</html>