2015-11-13 61 views
7

恢復的Tableau圖表的當前視圖狀態的問題:保存並通過JavaScript API

我怎麼能存儲 - 然後在以後檢索 - 一個的Tableau視圖的自定義狀態,通過JavaScript的API?

說明:

我的網站上,我們目前允許任何用戶進行協作的一組的Tableau意見納入供以後使用一個PowerPoint類的在線演示文稿。在我們當前的實現中,Tableau圖的狀態不會被存儲,因此用戶必須每次都在應用演示時使用他或她想要的過濾器,選擇工作表等。這是我們現在想要避免的。

爲最簡單的解決方案將是存儲和檢索的「分享」 -links通過底杆接口訪問的一個;這些鏈接包含當前視圖的狀態,但到目前爲止,我們還沒有做到這一點:首先,由於域問題,我們不能簡單地從嵌入代碼iframe中獲取共享鏈接;其次,API方法workbook.getUrl()似乎不包括當前視圖的狀態。

我currenty展望workbook.rememberCustomViewAsync(名稱)workbook.showCustomViewAsync(名稱)方法,這似乎是一個可行的解決方案。但是,我似乎無法從這兩種方法中得到任何明智的結果,因爲它們在運行時最終會給出模糊的,無信息的500錯誤。

示例文件,並且錯誤:

爲了更好地說明此問題,我已經創建了一個最小demo(下面片斷),試圖使用上述第二方法。在谷歌瀏覽器中打開時,兩種按鈕('保存狀態'和'檢索狀態')都不適用於我,並且可以在開發者工具中看到以下錯誤(分別爲http響應消息和開發者控制檯輸出):

HTTP響應:

<br> 
2015-11-11 16&#x3a;14&#x3a;17.916 
&#x28;VkNpWQrCQaIAACQo2YYAAAPi,0,0&#x29; 

控制檯錯誤:

POST http://public.tableau.com/vizql/w/Book6_426/v/YRKE/save_customized_view/sessions/208A699D34E14708A2268AA10A827C99-0:0 500 (Internal Server Error) 

有誰知道我怎麼能解決這個問題,無論是由希提供的代碼示例工作(描述的第二種方法)還是通過其他方式?任何幫助,將不勝感激!

PS:這裏的片段模擬器會導致訪問控制允許來源的錯誤。該文件也已發佈here

<html> 
 

 
<head> 
 
    <title>A simple Tableau API demo</title> 
 
    <!--script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script--> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> 
 
    <!--script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau_v8.js"></script--> 
 
    <script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.min.js "></script> 
 
</head> 
 

 
<body> 
 

 

 
    <H2>Custom view storage demo</H2> 
 

 
    <button id="remember-button"> 
 
    Remember state 'test' 
 
    </button> 
 
    <button id="retrieve-button"> 
 
    Retrieve state 'test' 
 
    </button> 
 

 
    <div id="viz-placeholder" style="width: 1000px; height: 1000px; display: block;"></div> 
 

 

 
    <script> 
 
    
 
    // Render tableau graph 
 
    function initializeViz() { 
 
     var placeholderDiv = document.getElementById("viz-placeholder"); 
 
     var url = "https://public.tableau.com/views/Book6_426/YRKE"; 
 
     var options = { 
 
     width: placeholderDiv.offsetWidth, 
 
     height: placeholderDiv.offsetHeight, 
 
     hideTabs: true, 
 
     hideToolbar: true, 
 
     onFirstInteractive: function() { 
 
      workbook = viz.getWorkbook(); 
 
      activeSheet = workbook.getActiveSheet(); 
 
     } 
 
     }; 
 
     viz = new tableau.Viz(placeholderDiv, url, options); 
 
    } 
 

 
    $(initializeViz) 
 

 
    
 
    // Assign and set up button actions for storing and retrieving the custom view 
 
    var customViewName = "test"; 
 

 
    $('#remember-button').click(function() { 
 
     console.log("Remembering: ", customViewName); 
 
     
 
     // Try to save state, or print error 
 
     viz.getWorkbook().rememberCustomViewAsync(customViewName).otherwise(function(err) { 
 
     console.log("An error occured:"); 
 
     console.log(err); 
 
     }); 
 
     
 
    }); 
 

 
    $('#retrieve-button').click(function() { 
 
     console.log("Retrieving: ", customViewName); 
 
     
 
     // Try to retrieve state, or print error 
 
     viz.getWorkbook().showCustomViewAsync(customViewName).otherwise(function(err) { 
 
     console.log("An error occured:"); 
 
     console.log(err); 
 
     }); 
 
     
 
    }); 
 
    </script> 
 

 

 
</body> 
 

 
</html>

回答

2

歐凱,所以我一直在用的Tableau客戶支持聯繫,他們似乎已經找到了問題。

顯然,javascript-API的某些元素僅適用於網上的Tableau和的Tableau服務器 - 的Tableau公開。

換句話說,Tableau Public託管的圖表不支持函數workbook.rememberCustomViewAsync('customViewName') - 例如以上示例中使用的圖表(https://public.tableau.com/views/...)。

+1

嘿,我有一個問題。我知道,自定義視圖是在一個工作簿中的所有儀表板之間共享的。有沒有辦法將具有相同過濾器的工作簿1的儀表板1的自定義視圖應用於工作簿2的儀表板2? –

+0

@DeepanshuKalra,恐怕我幫不了你。我建議你發佈一個問題官方支持論壇。他們最終幫助我! –