Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json Web数据连接器(Tableau)_Json_Tableau Api - Fatal编程技术网

Json Web数据连接器(Tableau)

Json Web数据连接器(Tableau),json,tableau-api,Json,Tableau Api,给定的是我创建的Web数据连接器页面的代码,它创建了一个URL来从API访问json数据 然后将json数据推送到一个数组上,然后将该数组馈送到tableau 我已经给出了下面的代码,请告诉我他们的代码中是否有错误,并帮助我解决问题 <html> <head> <title> Topic Call</title> <meta http-equiv="Content-Type" content="text/html; charset=us-a

给定的是我创建的
Web数据连接器页面
的代码,它创建了一个URL来从API访问json数据

然后将json数据推送到一个数组上,然后将该数组馈送到tableau

我已经给出了下面的代码,请告诉我他们的代码中是否有错误,并帮助我解决问题

<html>
<head>
<title> Topic Call</title>

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link href="http://fonts.googleapis.com/css?family=Didact+Gothic" rel="stylesheet" />

<link href="default.css" rel="stylesheet" type="text/css" media="all" />

<link href="fonts.css" rel="stylesheet" type="text/css" media="all" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>

<script src="https://online.tableau.com/javascripts/api/tableauwdc-1.1.0.js" type="text/javascript"></script>

<script type="text/javascript">
  (function() {

//HELPER FUNCTION USED TO BUILD THE API CALL.
    function buildUrl(option) {
        if(option==""){ 
                    var uri = "http://api.worldbank.org/topic?per_page=100&format=json";
                  }

              else{
                    var uri = "http://api.worldbank.org/topic/"+ option +"?per_page=100&format=json";
                  }
    return uri;
                       }

//Function to create an instance of the connector.
      var myConnector = tableau.makeConnector();

//Tableau calls this function to get column (field) information for the data that the connector provides.
      myConnector.getColumnHeaders = function() {
               var fieldNames = ['topic-id','topic-value','source-note'];
               var fieldTypes = ['string','string','string'];
               tableau.headersCallback(fieldNames, fieldTypes); //Passes information about the data schema to Tableau.
                                                }

//To get the data that's represented by the connector.
     myConnector.getTableData = function(lastRecordToken) {
                var dataToReturn = [];             
                var hasMoreData = false;          
                var ticker = tableau.connectionData;
                var connectionUrl = buildUrl(ticker);
                var xhr = $.ajax({                                       
                           url: connectionUrl,
                           dataType: 'json',
                               success: function (data) { 
                                       var ii;
                                       var length1 = data[0].total;
                                       for (ii = 0 ; ii < length1; ii++) 
                                         {
                                            var entry = {
                                           'topic-id':data[1][ii].id,
                                           'topic-value':data[1][ii].value,
                                           'source-note':data[1][ii].sourceNote
                                                        }; 
                                        dataToReturn.push(entry);
                                         }
                     console.log(dataToReturn);
        tableau.dataCallback(dataToReturn, lastRecordToken, false);//Passes data from the connector to Tableau
                                    },
//TO GET THE ERROR MESSAGE  
  error: function(xhr, ajaxOptions, thrownError) {           
          tableau.log("Connection error: " + xhr.responseText + "\n" + thrownError);
          tableau.abortWithError("Error while trying to connect to the World Bank data source.");
                         }       
                    });                   
              }
//Registers the connector with Tableau.
  tableau.registerConnector(myConnector);

//jQUERY USED FOR GETTING THE RESPONSE ON CLICKING THE BUTTON.  
  $(document).ready(function() {
                     $("#subGet").submit(function() {
                    var topic = $('#edit-topic').val();
                        if (topic) {
                        tableau.connectionName = "World Bank Data for " + topic;
                        tableau.connectionData = topic;//connectionData is used to pass information from the interactive phase to the data-fetching phase of the connector.
                        tableau.submit();//Tells Tableau that the connector has finished the interactive phase or the authentication phase. After this method is called, Tableau proceeds to the data-gathering phase.
                           }
                      });
                 });
            });
</script>
    <script src="https://public.tableau.com/javascripts/api/tableauwdc-1.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
    (function() {
        var myConnector = tableau.makeConnector();
        myConnector.getColumnHeaders = function() {}
        myConnector.getTableData = function(lastRecordToken) {}
        tableau.registerConnector(myConnector);
    })();
</script>
</head>

<body>
<div id="header-wrapper">
    <div id="wblogo"></div> 
    <div id="banner" class="container">
        <div class="title">
            <h2>TOPIC calls</h2>
            <span class="byline">Select one of the Topic mentioned below</span>
        </div>
    </div> 
</div>
<div id="decor1"> </div>
<div id="wrapper">
    <div id="three-column" class="container">
        <div class="title">
            <span class="byline">Topics : <select name="topic" class="form-select" id="edit-topic"> <option value="">-</option> <option value="1">Agriculture &amp; Rural Development</option> <option value="2">Aid Effectiveness</option> <option value="3">Economy &amp; Growth</option> <option value="4">Education</option> <option value="5">Energy &amp; Mining</option> <option value="6">Environment</option> <option value="7">Financial Sector</option> <option value="8">Health</option><option value="9">Infrastructure</option> <option value="10">Social Protection &amp; Labor</option> <option value="11">Poverty</option> <option value="12">Private Sector</option><option value="13">Public Sector</option> <option value="14">Science &amp; Technology</option> <option value="15">Social Development</option> <option value="16">Urban Development</option> <option value="17">Gender</option> <option value="18">Millenium development goals</option> <option value="19">Climate Change</option> <option value="20">External Debt</option> </select><p></p>

            <input type="submit" name="op" id="subGet" class="button button-alt" value="Get Data"></span>
        </div>      
    </div>
</div>
<div id="decor1"></div>
<div id="footer"></div>
</body>
</html>

主题电话
(功能(){
//用于构建API调用的助手函数。
函数buildUrl(选项){
如果(选项==“”){
var uri=”http://api.worldbank.org/topic?per_page=100&format=json";
}
否则{
var uri=”http://api.worldbank.org/topic/“+选项+”?每页=100&格式=json”;
}
返回uri;
}
//函数创建连接器的实例。
var myConnector=tableau.makeConnector();
//Tableau调用此函数以获取连接器提供的数据的列(字段)信息。
myConnector.getColumnHeaders=函数(){
var fieldNames=['topic-id','topic-value','source-note'];
var fieldTypes=['string','string','string'];
headersCallback(字段名,字段类型);//将有关数据架构的信息传递给tableau。
}
//获取由连接器表示的数据。
myConnector.getTableData=函数(lastRecordToken){
var dataToReturn=[];
var hasMoreData=false;
var ticker=表格连接数据;
var connectionUrl=buildUrl(ticker);
var xhr=$.ajax({
url:connectionUrl,
数据类型:“json”,
成功:函数(数据){
var ii;
var length1=数据[0]。总计;
对于(ii=0;ii

有两件事可以解决这个具体问题:

  • 更新指向的脚本标记,改为将其指向
  • 删除指向的重复脚本标记
  • 这两个版本的文件都很旧,而online.tableau.com上的文件实际上有一个bug(已经修复)。我们在web数据连接器的生命周期早期就搞砸了,没有正确地遵循。现在我们是。该库的所有未来版本都将遵循semver,并托管在connectors.tableau.com/libs上

    希望有帮助

    布伦丹