If you want something more efficient than a for loop:

$('#buttonAddSeries').click(function() {

    var series = chart.get('seriesId')
    var yData = series.processedYData
    var xData = series.processedXData
    var data = [];
    var period = 3;
    /* sumForAverage initialised to sum of yData indexed between 0 and period */
    var sumForAverage = yData.slice(0, period).reduce(function(prev, cur) {
        return prev + cur;
    /* Subset yData from period to end. */
    yDataWindow = yData.slice(period, yData.length)
    /* At each point add the new value and subtract yData[currentIndex]. */
    yDataWindow.reduce(function(previousValue, currentValue, currentIndex) {
        /* push each iteration to data */
        data.push([xData[currentIndex + period], previousValue/period])
        return previousValue + currentValue - yData[currentIndex]
      /* sumForAverage is passed as starting value */
    }, sumForAverage)
        name: 'Moving Average',
        data: data

Example: JS Fiddle with data


No, currently HighCharts does not do any data analysis like this. You would need to generate your own moving average and create that as its own series or plotLine/plotBand.


These days there is a plugin for Highcharts with which you can add a SMA (Simple Moving Average).



Moving averages are supported using the technical indicators plug-in found here

Here is a link to the JavaScript source that you'll need to include:

It is implemented by adding another series to the chart of type: 'trendline', algorithm: 'SMA' that refers to the relevant data series by id:

series : [
  name: 'AAPL Stock Price',
  type : 'line',
  id: 'primary',
  data : [100,101,105,107,104,105,106,104,...]
}, {
  name: '15-day SMA',
  linkedTo: 'primary',
  showInLegend: true,
  type: 'trendline',
  algorithm: 'SMA',
  periods: 15

Here is a JSFiddle.


you can calculate the moving average and add it like this:

$('#buttonAddSeries').click(function() {
    var series = chart.series[0];
    var data = [];
    var period = 2;
    var sumForAverage = 0;
    var i;
    for(i=0;i<;i++) {
        sumForAverage +=[i].y;
        if(i<period) {
        } else {
            sumForAverage -=[i-period].y;
            data.push([[i].x, sumForAverage/period]);
        name: 'Moving Average',
        data: data

You can use any number of points as the period, not only 2.

Related Query

More Query from same tag