Reputation: 27
I have a hard coded (but working) Meteor chart that includes
labels: ["January", "February", "March", "April", "May", "June", "July"],
and
data: [random(), random(), random(), random(), random(), random(), random()]
Now, I want to generate the labels and data lists from a mongo collection.
The mongo collection looks like
meteor:PRIMARY> db.stutterRatings.find()
{ "_id" : "qokM4aGwJH9ppXDBL", "rating" : "4", "date" : ISODate("2015-09-24T10:02:50.945Z") }
{ "_id" : "nC4ut3xzmu2fHH93w", "rating" : "3", "date" : ISODate("2015-09-24T10:02:56.716Z") }
{ "_id" : "wathoLgoN5HH8K4Dx", "rating" : "9", "date" : ISODate("2015-09-24T10:10:09.768Z") }
{ "_id" : "24ndAsJQQv6Akbdr5", "rating" : "10", "date" : ISODate("2015-09-24T10:33:19.044Z") }
The date
values will be used as labels and the rating
values will be used as data. How do I do this?
Upvotes: 0
Views: 1549
Reputation: 20788
1) fetch the data on the client:
var dataset = Data.find({<--whatever-query-you-need-->},{fields: {labels:1, rating:1}}).fetch()
2) map the field to what you need:
var labels = dataset.map(function(d) { return d.label; }
var data = dataset.map(function(d) {return d.rating; }
if you use d3js you may be able to just pass the data to the enter function and then the mapping function to each axis.
Upvotes: 1