首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tableau web数据连接器javascript不能使用blockchain.info api工作

Tableau web数据连接器javascript不能使用blockchain.info api工作
EN

Stack Overflow用户
提问于 2018-01-22 05:00:29
回答 1查看 401关注 0票数 0

我的代码似乎没有在tableau web数据连接器模拟器中生成表。我已经按照说明完成了他们所展示的教程。

请看这里的教程-https://tableau.github.io/webdataconnector/docs/wdc_tutorial

这可能是json的格式化方式,也可能是我试图将其转换为表的方式。

有关文档https://blockchain.info/api/charts_api,请参阅此处

请在此处查看json https://api.blockchain.info/charts/total-bitcoins?timespan=all&format=json

我是javascript的新手,还不知道为什么它不能运行……我可以让html页面在本地运行(按照说明)。

有没有人对我如何让这个(我的代码)工作有什么建议?我已经看过其他WDC,但仍然没有任何运气。

代码语言:javascript
复制
    (function () {
var myConnector = tableau.makeConnector();

myConnector.getSchema = function (schemaCallback) {
    var cols = [{
        id: "x",
        alias: "date",
        dataType: tableau.dataTypeEnum.float
    }, {
        id: "y",
        alias: "values",
        dataType: tableau.dataTypeEnum.float
    }];

    var tableSchema = {
        id: "bitcoin"
        alias: "total bitcoin"
        columns: cols
    };      

    schemaCallback([tableSchema]);
};

myConnector.getData = function(table, doneCallback) {
    $.getJSON("https://api.blockchain.info/charts/total-bitcoins?timespan=all&format=json", function(resp) {
        var feat = resp.features,
            tableData = [];

        // Iterate over the JSON object
        for (var i = 0, len = feat.length; i < len; i++) {
            tableData.push({
                "x": feat[i].values.x,
                "y": feat[i].values.y
            });
        }

        table.appendRows(tableData);
        doneCallback();
    });
};

tableau.registerConnector(myConnector);


$(document).ready(function() {
    $("#submitButton").click(function() {
        tableau.connectionName = "Bitcoin";
        tableau.submit();
    });
});
})();
EN

回答 1

Stack Overflow用户

发布于 2018-01-22 23:44:16

这是可行的

代码语言:javascript
复制
(function () {
var myConnector = tableau.makeConnector();

myConnector.getSchema = function (schemaCallback) {
    var cols = [{
        id: "x",
        alias: "date",
        dataType: tableau.dataTypeEnum.float
    }, {
        id: "y",
        alias: "values",
        dataType: tableau.dataTypeEnum.float
    }];

    var tableSchema = {
        id: "bitcoin",
        alias: "total bitcoin",
        columns: cols
    };

    schemaCallback([tableSchema]);
};

myConnector.getData = function(table, doneCallback) {
    $.getJSON("https://api.blockchain.info/charts/total-bitcoins?timespan=all&format=json", function(resp) {
        var feat = resp.values,
            tableData = [];

        // Iterate over the JSON object
        for (var i = 0, len = feat.length; i < len; i++) {
            tableData.push({
                "x": feat[i].x,
                "y": feat[i].y
            });
        }

        table.appendRows(tableData);
        doneCallback();
    });
};

tableau.registerConnector(myConnector);


$(document).ready(function() {
    $("#submitButton").click(function() {
        tableau.connectionName = "Bitcoin";
        tableau.submit();
    });
});
})();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48371671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档