hi i’m trying to build charts with data from mongodb
i’m trying to print chart “onrendered” template it is a good solution ?
meteor 1.3
simple json data from mongodb example
{ "_id" : "mu85zXyG2eA5d8ue5", "name" : "buyhistory", "createdAt" : ISODate("2016-04-05T15:38:05.640Z"), "volume" : [ "1041" ], "avg" : [ "804539361.10" ], "max" : [ "1048100000.00" ], "min" : [ "2300000.00" ], "ddev" : null, "median" : [ "1007005000.18" ], "percentile" : [ "1047882428.57" ] }
/server/server.js
Meteor.publish('evemarketpublish', function() { return Eveorder.find(); });
/client/client.js
Template.evemarket.onCreated(function() {
this.subscribe('evemarketpublish');
});
/client/client.js
function createChart(data) { //console.log(data); var stock = data; $('#container-area').highcharts('StockChart', { series: [{ type: 'line', name: 'Close', data: stock.data.map(function(item){ return { x: item.max, y: item.min }; }), tooltip: { valueDecimals: 2 } }] }); };
/client/client.js
Template.evemarket.rendered = function() { Tracker.autorun(function () { data = Eveorder.find({ name: "buyhistory" }); createChart(data); }); };
/client/client.html
<template name="evemarket">
<div id="container-area"></div>
</template>
`