I am testing canvas js , I have huge set of data sets of datasets thats updated every seconds to my chart , after I get around 1000 datasets , chart become too tiny and unreadable..
How Do i set zoom level to show last 100 data everytime I receive ticks , below is my code so far.I dont want to use shift() , because I am unable to pan back and see previous data..
window.onload = function () {
var dps = [];
var dpss = [];
var dpsss = [];
var chart = new CanvasJS.Chart("chartContainer", {
zoomEnabled:true,
panEnabled:true,
title :{
text: "Dynamic Spline Chart"
},
axisY: {
includeZero: false,
minimum: -200,
maximum: 200
},
axisY2: {
includeZero: false
},
data: [{
type: "stackedColumn",
markerSize: 0,
dataPoints: dps
},
{
type: "stackedColumn",
markerSize: 0,
dataPoints: dpss
},
{
type: "stackedColumn",
markerSize: 0,
dataPoints: dpsss
}]
});
var xVal = 0;
var yVal = 100;
var updateInterval = 1000;
var dataLength = 240; // number of dataPoints visible at any point
var updateChart = function (count) {
count = count || 1;
// count is number of times loop runs to generate random dataPoints.
for (var j = 0; j < count; j++) {
yVal = yVal + Math.round(5 + Math.random() *(-5-5));
yValx = yVal + Math.round(12 + Math.random() *(-5-5));
dps.push({
x: xVal,
y: yVal
});
dpss.push({
x: xVal,
y: -yValx
});
dpsss.push({
x: xVal,
y: -yVal
});
xVal++;
}
if (dps.length > dataLength) {
dps.shift();
dpss.shift();
dpsss.shift();
}
chart.render();
};
updateChart(dataLength);
setInterval(function(){ updateChart() }, updateInterval);
}