我的代码似乎没有在 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,但仍然没有任何运气。
(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();
});
});
})();