2016-10-24 50 views

回答

1

我做了类似的事情:我有一个包含脚本的“虚拟”数据源jsonscriptable的图表和一个函数,它们通过ajax在构建结果集的承诺中激活了不同的查询。然后,在图表的后读中,我刚刚返回了构建的结果集。

编辑

所以假设我在/ home/MYHOME仪表板testpromise 3个数据源返回结果集类似(即:相同的列数与同类型)。 在我的仪表板中,我实际上使用不同的参数调用了3次相同的查询:您将不得不调整代码。假设我们的图表被命名为mychart。 我有一个按钮(但它可以是任何东西)上点击动作下面的代码:

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&paramparam_annee='+a+'&paramparam_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); 
         }); 
} 
} 

图表与虚拟jsonscript数据源及其财产“执行在启动”设置为false有关。 postfetch物业:

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 
} 

玩得开心!

+0

你可以附加这个ajax函数,并在这里发布提取代码。 –

+0

是的,我必须找到代码的位置......我将在明天发布 – bhericher

+0

如何以及在哪里为每个图表栏添加不同的数据源? –

相关问题