The reason why this might be happing is that the data (this.data) context provided inside rendered
function is not reactive.
On Meteor 0.8.3 ( and maybe some other versions) there is an unofficial way of getting the data reactively, you have to dig into Meteor's source code to find it.
Template.piechart.rendered = function () {
this.autorun(function () {
//This is going to set a dependency
var myData = Blaze.getCurrentData();
//your code goes below
}
}
Use it at your own risk.
On Meteor 1.0 (as far as I know) there's is an official documented way. You use Template.currentData()
https://docs.meteor.com/#/full/template_currentdata
I personally used the rendered
function to create things like charts, etc. It's the kind of stuff that you only create once but you got to be very very careful about it.
Let's say you that in your application you have a list on the left and a main content area. On the list you can select different sets of data and when you click, the main content area gets loaded with your chart. Cool, it's working! But wait...
If you click on more items on the left side list, you notice that the page is getting slower. If you create your chart every single time you change the data content, your application is going to suffer and the UI gets frozen for some seconds. In my personal experience, I has this issue with a simple datetime picker. It's very common when the data context changes that the dependent functions will run more than once.
Solution:
Template.piechart.rendered = function () {
this.autorun(function (computation) {
//This is going to set a dependency
var myData = Template.currentData()
if (computation.firstRun) {
//create your pie chart, etc.
}
else{
//update the element(s) data that you create on first run
}
}
}