// To load chart
loadChart(): void {
let initialCardiacSamples = this.cardiacSamples;
this.ecgChart = Highcharts.chart(this.el.nativeElement, {
chart: {
type: 'line',
backgroundColor: '#4d2700',
},
title: {
text: 'ECG graph using Highcharts JS',
style: {
color: '#ffffff'
}
},
xAxis: {
type: 'number',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Amplitude',
style: {
color: '#ffffff'
}
},
gridLineWidth: 0,
minorGridLineWidth: 0,
max: 600
},
series: [{
name: 'ECG data',
data: initialCardiacSamples,
color: '#ffffff'
}]
});
}
// To update chart/ Calling update for every 300mili seconds here to take next data point
updateChart(): void {
let xAxisPoint = this.ecgChunkSize;
this.interval = setInterval(() => {
// Call addData() function to add next trace point to the graph
this.addDataPoint(this.ecgChunkSize, xAxisPoint);
this.ecgChunkSize = this.ecgChunkSize + 1;
xAxisPoint = xAxisPoint + 1;
if(this.ecgChunkSize == this.ecgFileSize) {
this.ecgChunkSize = 0;
}
}, 300);
}
// Method to add data and update the chart to make the graph real time
addDataPoint(index: number, xAxisPoint: number) : void {
let iy = this.cardiacSamples[index].y;
this.ecgChart.series[0].addPoint([xAxisPoint, iy], true, true);
//Calling addDataPoint() above with redraw chart and shift as true
}
.chart-container {
display: block;
margin:0;
position: relative;
height: calc(100vh - 450px - 40px);
padding-top: 0;
}
<div #highchartsEcg class="chart-container"></div>
Here, I am calling updateChart() with addPoint() for every 300 miliseconds. With this interval it is very slower, but maintaining somewhat graph shape. But, if I call updateChart() with <=100 miliseconds, graph completely collapse and loses its shape. I need faster movement of graph for ECG, trying with Angular5 application. Find attached images of ECG graphs. Normal graph shape with 300ms interval Graph shape collapse with 100ms interval