将tabletop.js与d3.js集成?

时间:2013-08-23 22:43:47

标签: json d3.js google-sheets tabletop.js

我想使用tabletop为我的d3可视化中的数据引用谷歌电子表格。我能想到的最好的解决方案就是这个,但我知道这不太对。

window.onload = function() { init() };

var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html';

function init() {
  Tabletop.init( { key: public_spreadsheet_url,
                 callback: showInfo,
                 simpleSheet: true } )
}

d3.json("showInfo", function(data) {
  console.log(data);
});

1 个答案:

答案 0 :(得分:2)

数据已经作为数组出现(参见下面的输出);所以没有必要申请d3.json。您可以立即开始使用数组进行d3可视化。

window.onload = function() { init() };
var public_spreadsheet_url = "https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html";
function init() {
    Tabletop.init( { key: public_spreadsheet_url,
        callback: showInfo,
        simpleSheet: true } )
}
function showInfo(rows) {
    console.log(rows);
    // build your d3 vis here..
}

enter image description here