Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement moving average in highchart

Tags:

highcharts

I want to implement moving average in hightchart. Is there any option in highchart for this.

Like: I have series 10, 20, 30, 40, 50, 60, 70

and here the moving average would be 2.

Then second series will generate on average values of series 1

like: 15, 35, 105 (taking average of each two datapoints)

And embedding this moving average series of series1 on the same chart.

like image 857
abhishek mehra Avatar asked Jul 08 '13 09:07

abhishek mehra


People also ask

What is a moving average in statistics?

In normal mean, it’s value get changed with the changing data but in this type of mean it also changes with the time interval . We get the mean for some period t and then we remove some previous data . Again we get new mean and this process continues . This is why it is moving average . This have a great application in financial market . Examples:

How to set the moving average length as a power of two?

This condition is implemented using a synchronous reset “ i_sync_reset ”. This VHDL implementation of moving average algorithm configures the moving average length as a power of two. The generic value for moving average length is passed as log2 value so it will be simple to perform the output right shift.

What is the generic value for moving average length in VHDL?

The generic value for moving average length is passed as log2 value so it will be simple to perform the output right shift. In the next figures is reported a ModelSim simulation of the VHDL code implementing moving average algorithm. Figure3 is relative to input sample with continuous data enable.

How do you find the first element of a moving average?

Approach Given a series of numbers and a fixed subset size, the first element of the moving average is obtained by taking the average of the initial fixed subset of the number series. Then the subset is modified by “shifting forward”, i.e excluding the first number of the series and including the next value in the subset.


1 Answers

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<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]);
        }
    }
    chart.addSeries({
        name: 'Moving Average',
        data: data
    });
});

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

like image 135
meir shapiro Avatar answered Jan 04 '23 21:01

meir shapiro