我的代码似乎没有在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();
});
});
})();
答案 0 :(得分:0)
这有效
(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();
});
});
})();