I have to plot a graph based on the data values v/s time {x-axis= time[] ,y-axis = data1[]}. I want to extrapolate this array and then plot the graph . I used the following code is this the correct way to do so?
function interpolateArray(data, fitCount) {
var linearInterpolate = function (before, after, atPoint) {
return before + (after - before) * atPoint;
};
var newData = new Array();
var springFactor = new Number((data.length - 1) / (fitCount - 1));
newData[0] = data[0]; // for new allocation
for ( var i = 1; i < fitCount - 1; i++) {
var tmp = i * springFactor;
var before = new Number(Math.floor(tmp)).toFixed();
var after = new Number(Math.ceil(tmp)).toFixed();
var atPoint = tmp - before;
newData[i] = linearInterpolate(data[before], data[after], atPoint);
}
newData[fitCount - 1] = data[data.length - 1]; // for new allocation
return newData;
};
data1 = interpolateArray(data1,(data1.length*2))
data2 = interpolateArray(data2,(data2.length*2))
and then I converted date in epoch time and then did the same and converted back to utc time , like this
Timestamp11=interpolateArray(Timestamp11,(Timestamp11.length*2))
for(var i=0;i<Timestamp11.length;i++)
{
console.log(Timestamp11[i]);
var edgeTime11=Timestamp11[i]/1000000
var myDate11 = new Date(Time11)
var utcString = myDate11.toString();
var time = utcString.slice(16, 24);
Timestamp11[i] = time;}
window.myLine3 = new Chart(ctx3, charInit3(data1, data2, Timestamp11));
Is it the correct way to extrapolate a time series data?? if not please correct me.