For example we have static implementation of chart js with data that we can’t update
JS
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import Chart from 'chart.js';
import './barChart.html'
let barChartData = {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: 'My First dataset',
data: [11, 22, 33, 44, 55, 66],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
}
let barChartOptions = {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
Template.barChart.helpers(barChartData);
Template.barChart.helpers(barChartOptions);
Template.barChart.onRendered(function () {
console.log("barChart is rendered")
let ctx = $("#barChart");
let myBarChart = new Chart(ctx, {
type : 'bar',
data : barChartData,
options: barChartOptions
});
});
Example HTML
{{> barChart}}
<template name='barChart'>
<canvas id="barChart" width="400" height="200"></canvas>
</template>
How to pass data/options to Chart JS from (local collection or server collection or some query), using Template helpers for updating chart in live? or for testing update that data from console