Using the Tableau JavaScript API

If you're a web application developer, you can control the Tableau JavaScript library using your own external web logic. For example, you may have dynamic, server-side logic outside of Tableau that determines the identity of the currently logged in user. You can use that logic to control the Tableau JavaScript and, in particular, the filter parameter—so that the current user only sees data that pertains to him or her. Here's an example to get you started:

<script type="text/javascript" src="http://myserver/javascripts/api/viz_v1.js"></script> 
<object class="tableauViz" width="800" height="600" style="display:none;"> 
  <param name="site_root" value="/t/Site" /> 
  <param name="name" value="Workbook/ViewName/<username>@domain/<custom_view_name>" /> 
  <param name="tabs" value="yes" /> 
  <param name="toolbar" value="yes" /> 
<script type="text/javascript"> 
        function useVizAPI() { 
              var viz = window.tableau.vizs[0]; 
              //viz.filter({Product: ['Mint', 'Green Tea']}); 
         if (document.addEventListener) { 
                 window.addEventListener("load", useVizAPI, false); 
         } else if (document.attachEvent) { 
                 window.attachEvent("onload", useVizAPI); 

The above functions are available at or after the browser's 'onload' event. Also, the argument to the filter function must be a JavaScript hash where the keys are dimension names and the value is either a string or an array of strings. The example above uses an array. Here's an example that uses a single string value: viz.filter({Product: ['Mint']})

Example Code Location

Web application example code for SharePoint, PHP, Ruby, and Java applications is installed with Tableau Server and is located in:

  • 32-bit: C:\Program Files\Tableau\Tableau Server\7.0\extras\embedding
  • 64-bit: C:\Program Files (x86)\Tableau\Tableau Server\7.0\extras\embedding