I am trying to implement a Moving Average line in a Highachart’s Scattered chart. The x Axis is a Date and y axis is days but when I try to calculate the Moving average its is referring to date with year 1970.
Here is js fiddle link for my code:
enter link description here
I also have code without moving Average and the link is enter link description here
Here is the Highchart code with Moving average I am using :
Highcharts.chart('container', {
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Height Versus Weight of 507 Individuals by Gender'
},
subtitle: {
text: 'Source: Heinz 2003'
},
xAxis: {
title: {
enabled: true,
text: 'PR Creation'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true,
type: 'datetime',
dateTimeLabelFormats: {
second: '%Y-%m-%d<br/>%H:%M:%S',
minute: '%Y-%m-%d<br/>%H:%M',
hour: '%Y-%m-%d<br/>%H:%M',
day: '%Y<br/>%m-%d',
week: '%Y<br/>%m-%d',
month: '%Y-%m',
year: '%Y'
}
},
yAxis: {
title: {
text: 'duration'
},
type: 'datetime', //y-axis will be in milliseconds
dateTimeLabelFormats: {
minute: '%H:%M'
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
backgroundColor: Highcharts.defaultOptions.chart.backgroundColor,
borderWidth: 1
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x}'
}
}
},
series: [{
name: 'PR',
color: 'rgba(223, 83, 83, .5)',
data: [{x:st4,y:3},{x:st5,y:7},{x:st6,y:8},{x:st7,y:9},{x:st8,y:9},{x:st9,y:7},{x:st10,y:7},{x:st11,y:3},{x:st12,y:2}]
},
{
name: 'PR',
color: 'green',
data: [{x:st,y:5},{x:st3,y:7},{x:st11,y:1}]
}]
}
,function() {
var Highcharts = this;
var series = Highcharts.series[0];
var data = [];
var period = 2;
var sumForAverage = 0;
var i;
for(i=0;i<series.data.length;i++) {
sumForAverage += series.data[i].y;
if(i<period) {
data.push(null);
} else {
sumForAverage -= series.data[i-period].y;
data.push([series.data[i].x, sumForAverage/period]);
}
}
Highcharts.addSeries({
name: 'Moving Average',
data: data
});
});
Please suggest if you have an idea on calculating the moving average . I am trying to implement something similar to the cycle time widget in Azure Devops