The code snippet has been attached. In the HomeComponent class, there is a method called rand()
that I need to call for the y-axis. However, in the current scenario, this is not possible because when onRefresh()
is called, this.rand()
is unreachable. This behavior is expected as onRefresh()
is called from core.js which is part of the core library. Any assistance on resolving this issue would be greatly appreciated.
export class HomeComponent implements OnInit, OnDestroy {
....
..
options: any = {
scales: {
xAxes: [
{
type: 'realtime',
realtime: {
onRefresh(chart: any) {
chart.data.datasets.forEach(function(dataset: any) {
dataset.data.push({
x: Date.now(),
**y: this.rand()**
});
});
chart.config.options.scales.yAxes[0].ticks.min = chart.helpers.niceNum(20);
chart.config.options.scales.yAxes[0].ticks.max = chart.helpers.niceNum(180);
},
delay: 2000
}
]
},
annotation: {
annotations: [
{
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: '120',
borderColor: 'tomato',
borderWidth: 2
},
{
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: '70',
borderColor: 'blue',
borderWidth: 2
}
]
//drawTime: "afterDraw" // (default)
}
};
....
....
rand(): Number {
return Math.floor(Math.random() * (200 - 100 + 1)) + 100;
}
}
Thank you in advance :)