通过javascript API保存和恢复Tableau图形的当前视图状态

前端之家收集整理的这篇文章主要介绍了通过javascript API保存和恢复Tableau图形的当前视图状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
问题:

如何通过javascript-API存储 – 然后检索 – Tableau视图的自定义状态?

描述:

我正在开发一个网站,我们目前允许任何用户将一组Tableau视图协作到类似PowerPoint的在线演示文稿中供以后使用.在我们当前的实现中,Tableau图的状态不会被存储,因此用户必须在每次持有演示文稿的同时应用他或她的所需过滤器,选择工作表等.这是我们现在想要避免的.

对此最简单的解决方案是存储和检索通过底栏界面访问的“共享”链接之一;这些链接包含当前视图的状态,但到目前为止,我们无法做到这一点:首先,由于域问题,我们不能简单地从嵌入代码iframe中获取Share-links;其次,API方法workbook.getUrl()似乎不包括当前视图的状态.

我目前正在研究workbook.rememberCustomViewAsync(name)和workbook.showCustomViewAsync(name)方法,这看起来像是一种可能的解决方案.但是,我似乎无法从这两种方法中得到任何明智的结果,因为它们最终都会在运行时产生模糊的,无信息的500错误.

示例文件错误

为了更好地说明这个问题,我创建了一个最小的demo(下面的代码段),尝试使用上述第二种方法.在Google Chrome中打开时,两个按钮(“保存状态”和“检索状态”)都不适用于我,并且可以在开发人员工具中看到以下错误(分别是http响应消息和开发人员控制台输出):

Http响应:

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

控制台错误

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

有没有人知道如何解决这个问题,或者通过提供代码示例(所描述的第二种方法),或通过任何其他方式?任何帮助,将不胜感激!

PS:此处的片段模拟器将导致Access-Control-Allow-Origin错误.该文件也已于here发布.

  1. <html>
  2.  
  3. <head>
  4. <title>A simple Tableau API demo</title>
  5. <!--script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script-->
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  7. <!--script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau_v8.js"></script-->
  8. <script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.min.js "></script>
  9. </head>
  10.  
  11. <body>
  12.  
  13.  
  14. <H2>Custom view storage demo</H2>
  15.  
  16. <button id="remember-button">
  17. Remember state 'test'
  18. </button>
  19. <button id="retrieve-button">
  20. Retrieve state 'test'
  21. </button>
  22.  
  23. <div id="viz-placeholder" style="width: 1000px; height: 1000px; display: block;"></div>
  24.  
  25.  
  26. <script>
  27. // Render tableau graph
  28. function initializeViz() {
  29. var placeholderDiv = document.getElementById("viz-placeholder");
  30. var url = "https://public.tableau.com/views/Book6_426/YRKE";
  31. var options = {
  32. width: placeholderDiv.offsetWidth,height: placeholderDiv.offsetHeight,hideTabs: true,hideToolbar: true,onFirstInteractive: function() {
  33. workbook = viz.getWorkbook();
  34. activeSheet = workbook.getActiveSheet();
  35. }
  36. };
  37. viz = new tableau.Viz(placeholderDiv,url,options);
  38. }
  39.  
  40. $(initializeViz)
  41.  
  42. // Assign and set up button actions for storing and retrieving the custom view
  43. var customViewName = "test";
  44.  
  45. $('#remember-button').click(function() {
  46. console.log("Remembering: ",customViewName);
  47. // Try to save state,or print error
  48. viz.getWorkbook().rememberCustomViewAsync(customViewName).otherwise(function(err) {
  49. console.log("An error occured:");
  50. console.log(err);
  51. });
  52. });
  53.  
  54. $('#retrieve-button').click(function() {
  55. console.log("Retrieving: ",customViewName);
  56. // Try to retrieve state,or print error
  57. viz.getWorkbook().showCustomViewAsync(customViewName).otherwise(function(err) {
  58. console.log("An error occured:");
  59. console.log(err);
  60. });
  61. });
  62. </script>
  63.  
  64.  
  65. </body>
  66.  
  67. </html>

解决方法

Okey,所以我一直与Tableau客户支持联系,他们似乎找到了这个问题.

显然,javascript-API的某些元素仅适用于Tableau Online和Tableau Server,而不适用于Tableau Public.

换句话说,Tableau Public托管的图形不支持函数workbook.rememberCustomViewAsync(‘customViewName’) – 例如上面示例中使用的图形(https://public.tableau.com/views / …) .

猜你在找的JavaScript相关文章