Hello,
I made a chart with c3.js :
And this is the code to render it :
Template.summary.rendered = function() {
var self = this;
var chart = c3.generate({
bindto: this.find('#gameGapChart'),
data: {
xs: {
'data1': 'x'
},
columns: [
['data1']
]
},
axis: {
x: {
show: false
}
}
});
this.autorun(function(tracker) {
var gameData = self.data.gameStats.evolution;
var xArray = ['x'];
var yArray = ['data1'];
for (var i = 0; i < gameData.length; i++) {
xArray.push(gameData[i][0]);
yArray.push(gameData[i][1]);
}
chart.load({
columns: [
xArray,
yArray, []
]
});
});
};
self.data.gameStats.evolution is the data available in the Template in the form :
"gameStats" : {
...
"evolution" : [
[0, 0],
[1, 3],
[2, 1],
[3, 4],
[4, 3],
...
]
...
}
The first value is the xAxis value and the second is for the yAxis value.
I can’t make the chart dynamic in the way that everytime gameStats.evolution got a new value the chart update. Right now, I need the refresh the page to see the chart been updated.
Can somebody help me make the chart dynamic via the database and not the Session variable.
Thanks in advance.