1 Reply Latest reply on Sep 1, 2016 2:27 PM by diego.medrano

    JavaScript API not responding

    Prophecy Nxumalo

      Hi I am new in using JavaScript API. I got the script from one of the sources online and changed few things like URL. I don't know whether I am on the right path I have been testing the script to the browser but it is not showing up any results. Please help me:

       

      Here is the script below.

       

      <html>

      <head>

          <title>Testing</title>

          <script type="text/javascript" src="https://10ay.online.tableau.com/javascripts/api/viz_v1.js"></script>

          <script type="text/javascript">

         

          var viz, workbook;

       

          window.onload() =function(){

          var vizDiz = document.getElementById('viz');

          var vizURL = 'SERVER-NAME/views/visualization';

          var options = {

              width: '600px',

              height: '540px',

              hideToolbar: true,

              hideTabs: true,

              onFirstInteractive: function(){

                 

                  document.getElementById('sheetName').innerHTML = viz.getWorkbook().getActiveSheet().getNam

              }

          }

          viz = new tableauSoftware.Viz(vizDiz,vizURL, options);

         

      };

       

      function switchView(sheetName){

         

                  workbook = viz.getWorkbook();

                  workbook.activeSheetAsync(sheetName);

         

      }

       

       

      function showOnly (filterName, values){

         

                  sheet = viz.getWorkbook().getActiveSheet();

              if    (sheet.getSheetType() == 'worksheet'){

                  sheet.applyFilterAsync(filterName,values, 'REPLACE');

          }    else {

                  worksheetArray = sheet.getWorksheets();

              for(var i = 0; i<worksheetArray.length; i++){

                  worksheetArray[i].applyFilterAsync(filterName, values, 'REPLACE');

              }

          }

       

      }

       

      function selectMarks(filterName, values){

         

                  sheet = viz.getWorkbook().getActiveSheet();

          if        (sheet.getSheetType() ==  'worksheet'){

                  sheet.selectMarksAsync(filterName,values, 'REPLACE');

          }

          else {

                  worksheetArray = sheet.getWorksheets();

          for        (var i=0;i<worksheetArray.length; i++){

                  worksheetArray[i].selectMarksAsync(filterName,values, 'REPLACE');   

              }

          }

      }

       

      </script>

      </head>

      <body>

          <h2>Data</h2>

         

         

          <div>

              <a onClick="switchView('QtyOnHandOverTime')">Qty On Hand Over Time</a> |

              <a onClick="switchView('DailySalesReport')">Daily Sales Report</a> |

      <!--    <a onClick="showOnly('Category','Book')">Show Only Books</a> |

              <a onClick="selectMarks('Category','Book')">Select Books</a> -->

          </div>

         

         

          <div id='viz'></div>

         

         

         

      </body>

      </html>