Hightcharts from mongodb data

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>

`

That looks about right, with a couple of issues: you don’t have a data object in stock, and you will redraw the entire chart every time you get a new data point. It would be better to just alter the data and make use of Highcharts’ ability to shift the series display dynamically.

the idea is to refresh my graphics for each new database input, this is not a good solution for you?

I think it makes sense that the series redraws with a new data point, like this: http://www.highcharts.com/demo/dynamic-update

But at the moment your code will completely redraw the whole chart on a new point.

A couple more issues: you have no sorting on your finds, which means that data points may not be processed in the correct order. Also, the Template.xxx.rendered = function syntax is deprecated and should be replaced with

Template.onRendered(function() {
  // code here
});