简体   繁体   中英

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?

UPDATE: I'm trying out deps.autorun... as per this SO thread and @ethaan's answer below. 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).

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. However, The chart is not reactive. If I change the .tsv file, the data in the chart does not change....


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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