Reputation: 476
I am using pentaho CDE.
Is there a way, that I can provide a different datasource (MySQL query) for each bar of a CCC stacked bar chart ?
Upvotes: 1
Views: 783
Reputation: 667
I did something similar : I had a chart with a "dummy" datasource jsonscriptable over scripting and a function that, via ajax , activated different queries within a promise for building a resultset. Then, in the postfetch of the chart, I just returned the built resultset.
Edit
So assume I have the dashboard testpromise in /home/myhome with 3 datasources returning a similar resultset (that is : the same number of columns with the same types). In my dashboard, I have in fact the same query invoked 3 times with different parameters : you will have to adjust the code. Let's say that our chart is named mychart. I have a button (but it can be anything else) with the following code on click action :
function(){
Dashboards.res=[];//will contain the result ; As for Pentaho 5.4 without RequireJS, Dashboards is a global varialbe, so that Dashboards.res is accessible eveywhere
Promise.all([getib3(2016,3),getib3(2015,3),getib3(2016,8)]).then(
function(r){
//res contains the result of the 3 queries
console.log(res);
Dashboards.etComponentByName('render_mychart').update(); //Activates the chart
},
function(err) {
console.error(err);
}
);
function getib3(a,m){
var postquery='path=%2Fhome%2myhome%Ftestpromise.cda&dataAccessId=sql_get_ib3¶mparam_annee='+a+'¶mparam_mois=' +m;
$.ajax({
url: '/pentaho/plugin/cda/api/doQuery?',
type: 'POST',
dataType: 'json',
data: postquery,
// async:false,
}).done(function (data) { console.log(data) ;
res.push(data.resultset);//ad the result of the query
}).fail(function ( jqXHR, textStatus, errorThrown) {
alert('query :' + textStatus);
});
}
}
The chart is associated with a dummy jsonscript datasource its property "execute at start" is set to false . The postfetch property :
function(d) {//d is the resultset of the dummy datasource, here we can ignore it.
return (Dashboards.res); //We override d with the resultset we build above
}
Have fun!
Upvotes: 1