0

My code does not seem to generate a table in the tableau web data connector simulator. I have followed the instructions and worked off the tutorial they showed.

See here for the tutorial -https://tableau.github.io/webdataconnector/docs/wdc_tutorial.

It could be the way the json is formatted and how i have tried to turn it onto a table.

see here for the docs https://blockchain.info/api/charts_api

see here for the json https://api.blockchain.info/charts/total-bitcoins?timespan=all&format=json

I am a newb at javascript and havent got a clue why it wont run... i can get the html page to run locally (as per the instructions).

Does anyone have any suggestions as to how i can get this (my code) to work? I have looked at other WDCs but am still not having any luck.

    (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();
    });
});
})();

1 Answers1

0

This works

(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();
    });
});
})();
arnoldtm
  • 77
  • 12
  • Still no luck.. will post my html later when I get home so you can see the full picture... any other ideas though? – James Sherborne Jan 26 '18 at 16:59
  • @JamesSherborne, Sorry for taking long to give you the answer got caught up in other things. However, this should work as I have tested with WDC SDK Simulator. Cheers – arnoldtm Feb 07 '18 at 16:56