Running a BQL Query 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){
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
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 );
document.getElementById("result").value=JSON.stringify(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>