d3.js - MongoDB Collection as data source for cs.js in Meteor app -


as title says i'm using c3.js plot charts in meteor app. examples, however, statically set variables data source.

i can't find correct way use c3 mongo. have simple template below

<template name="model1">     <div class="chart"></div> </template> 

and chart code follows

template.model1.rendered = function () {     var chart = c3.generate({         bindto: this.find('.chart'),         data: {             json: [                 {name: 'www.site1.com', upload: 100                     , download: 200, total: 400}             ],             keys: {                 value: ['upload', 'download']             }         },         axis: {             x: {                 // type: 'category'             }         }     }); }; 

how can populate json field result of querying mongo, models.find({"model" : "model1"},{"actual" : 1, "_id": 0}).

running equivalent mongo shell db.models.find({"model" : "model1"},{"actual" : 1, "_id": 0}) returns {"actual" : [ 1, 2, 3 ] }

i can't figure out how approach this

you can define meteor.methods , meteor.call retrieve data , populate d3.

methods.js

meteor.methods({    data: function(){      check(arguments, [match.any]);      return models.find({"model" : "model1"},{"actual" : 1, "_id": 0}).fetch();    }  }); 

template.html

template.model1.onrendered(function () {    var self = this;    meteor.call('data', function (error, result) {      var chart = c3.generate({       bindto: self.find('.chart'),       data: {         json: result,         keys: {           value: ['upload', 'download']         }       },       axis: {         x: {           // type: 'category'         }       }     });    });  }); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -