On 28 September 2016 at 23:57, Julian Knight <
j.kni...@gmail.com> wrote:
> I think that you can access the msg object in the Angular (browser) script
> by accessing the "scope" variable?
>
> The following works:
>
> <div ng-bind-html="msg.payload"></div>
> <script>
> ;(function(scope) {
> //console.dir(scope.msg) // This doesn't work
> scope.$watch('msg.payload', function() {
> console.dir(scope.msg) // This DOES work
> })
> })(scope)
> </script>
I think that is the technique proposed in the link I posted.
Coincidentally I have been working on exactly the same problem - that
of using chart.js in a template node and providing it dynamic data.
This is what I have got so far, which does seem to work ok.
<script src="/Chart.bundle.min.js"></script>
<h3>Testing dynamic chart.js with Dashboard 2.0</h3>
<canvas id="myChart" width="50" height="50"></canvas>
<script>
var chartDef = {
type: 'line',
data: {
datasets: [{
label: "temperature",
fill: false,
lineTension: 0,
borderColor: "#00ff00",
pointRadius: 0,
pointBorderColor: "#ff0000",
pointBackgroundColor: "#0000ff",
borderWidth: 1,
data: [] // data is written here later
}, {
label: "setpoint",
fill: false,
lineTension: 0,
borderColor: "#ff0000",
pointRadius: 0,
pointBorderColor: "#ff0000",
pointBackgroundColor: "#ff0000",
borderWidth: 1,
data: [] // data is written here later
}]
},
options: {
scales: {
xAxes: [{
type: 'time',
displayFormats: {
minute: 'hh:mm:ss',
}
}],
yAxes: [{
ticks: {
min: 10,
max: 25,
stepSize: 1
}
}]
},
animation: {
duration: 0
}
}
}
function doChart(dataPoints) {
var ctx = document.getElementById("myChart");
for (var i = 0; i < dataPoints.length; i++) {
chartDef.data.datasets[i].data = dataPoints[i];
}
var myChart = new Chart(ctx, chartDef);
};
(function(scope) {
scope.$watch('msg.payload', function(payload) {
if (payload) {
doChart(payload);
}
});
})(scope);
</script>
The above draws the chart as defined by chartDef (which is a line
chart with two lines) with the data points provided in msg.payload as
array of two arrays of data points. So something like
[[{x:1,y:1},{x:2,y:2}],[{x:1,y:4},{x:2,y:3}]].
I want to work refine it so that it does not recreate the chart every
time it gets a new payload but reuses the existing chart, just
updating the data it is displaying.
Colin
>
>
>
> On Wednesday, 28 September 2016 13:48:03 UTC+1, Dave C-J wrote:
>>
>> The dashboard template uses angular not moustache - so although it uses {{
>> a lot it's not the same :-(
>>
>> Rught now you would need to do that using a normal (non-ui) template node
>> first then feed that into the ui-template to render.
>
>
https://groups.google.com/d/msgid/node-red/575e1592-28e4-4f84-922e-cc67b20ffdb8%40googlegroups.com.