简体   繁体   English

在Meteor中,如何从.tsv文件导入数据以在d3.js图表​​中使用?

[英]In Meteor, how can I import data from a .tsv file to use in a d3.js chart?

When I call a function like the following, the data object comes out undefined, and the chart won't render. 当我调用如下函数时,数据对象未定义,图表将不会呈现。 How can I import this data using Meteor? 如何使用Meteor导入此数据?

UPDATE: I'm trying out deps.autorun... as per this SO thread and @ethaan's answer below. 更新:我正在尝试deps.autorun...根据此SO线程和下面的@ethaan的答案。 This got my chart to render. 这使我的图表得以呈现。

However , oddly enough, it renders with completely the wrong dataset. 但是 ,奇怪的是,它使用完全错误的数据集进行渲染。 Very interesting... Here's the link to the current state of my project on github: https://github.com/goodwordalchemy/Reactive-line-graph-with-meteor/tree/master/barChart_pt2-meteor Check out waffles.tsv (changed name to distinguish from old file named data.tsv, which d3 seems to be loading). 非常有趣...这是我在github上项目的当前状态的链接: https : //github.com/goodwordalchemy/Reactive-line-graph-with-meteor/tree/master/barChart_pt2-meteor查看waffles.tsv (更改名称以区别名为d3的旧文件data.tsv)。

And here is a screenshot of what's getting rendered: 这是正在渲染的屏幕截图: 但是是正在渲染的屏幕截图

UPDATE II: As per this SO article I moved my data file into the public folder, and I am able to render my chart in the browser. 更新II:根据这篇SO文章,我将数据文件移到了公共文件夹中,并且能够在浏览器中呈现图表。 However, The chart is not reactive. 但是,该图表不是被动的。 If I change the .tsv file, the data in the chart does not change.... 如果更改.tsv文件,则图表中的数据不会更改。


Template.d3chart.rendered = function(){

    // chart attributes and scale are defined up here...

    var chart = d3.select(".chart")

    d3.tsv("data.tsv", type, function(error, data) {
      // callback function
    }
}
Template.d3chart.rendered = function(){ 
    // chart attributes and scale are defined up here...
    Tracker.autorun(function(){
     var chart = d3.select(".chart")
    d3.tsv("data.tsv", type, function(error, data) {
      // callback function
    }
 })

}

Typo on rendered?, render dosn't exists 渲染上的错别字?,渲染不存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM