Home Forums Chart Support Help with Dynamic chart, please !!! Reply To: Help with Dynamic chart, please !!!

#10579

Dear Mr.Sanjoy, I did try your advice and I thought the problem is still exist somewhere in updateChart() function.

Let’s get back to my data example :

if (!!window.EventSource) {
document.addEventListener( 'DOMContentLoaded', function () {
	if (!!window.EventSource) {
		var source = new EventSource('data');
		source.addEventListener('message', function(e) {      
            for(var k = 0; k < e.data.length; k++) {
               yVal = parseInt(e.data.substr(k, 5)));
	         }
		}, false);
	}
	else {
		console.log('sse not supported');
	}
}, false );

Here you can see I’ve add up yVal variable to store the data. This time, the signal will be plot with the old updateChart() function :

	var updateChart = function (count) {
			var count = count || 1;
			for (var j = 0; j < count; j++) {
				xVal ++;
				dps[xVal % dataLength].y = yVal;
				dps[(xVal+gap) % dataLength].y = null;
			};
			chart.render();		
		};

However, the plotted signal is still depend on setInterval() function and the result is wrong, indeed.

Ok, I changed the updateChart() function with your code above :

var updateChart = function (yVal) {
			
			xVal ++;
			dps[xVal % dataLength].y = yVal;
			dps[(xVal+gap) % dataLength].y = null;
			chart.render();		
		};

With this one, the signal has not been plotted even though I removed or keep the setInterval() as well.