2016-10-24 47 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

如何以及在哪裏爲每個圖表欄添加不同的數據源? –

相關問題