# Moving Average

Learn how to add moving average analysis to Wijmo's chart components in this documentation topic

## Content

The __wijmo.chart.analytics__ module contains classes that extend the __Series__ class to provide extra information about the data including: trend lines, moving averages, error bars, box and waterfall plots, and function plots.

The __MovingAverage__ class extends the regular __Series__ class to provide a series of averages of different subsets of the full data set.

To add moving averages to a chart, follow these steps:

1. Create one or more __MovingAverage__ series,
2. Configure the __MovingAverage__ series as you would regular series, setting their __binding__, __chartType__, and __style__ properties for example, and
3. Set the MovingAverage's __type__ and __period__ properties to determine the type of moving average you want to create.

Example:

```JavaScript
import * as chart from '@mescius/wijmo.chart';
import * as analytics from '@mescius/wijmo.chart.analytics';

// create a MovingAverage and add it to the Chart series collection
var movingAvg = new analytics.MovingAverage();
movingAvg.name = 'Moving Average';
movingAvg.itemsSource = myChart.itemsSource;
movingAvg.binding = 'sales';
movingAvg.type = 'Simple';
movingAvg.period = 6;
movingAvg.style = { stroke: 'darkred', strokeWidth: 3 };
myChart.series.push(movingAvg);
```
![Chart Moving Average](https://cdn.mescius.io/document-site-files/images/3c7113e2-10b3-45ed-8f3b-9fb1e0af2b74/chart/chart-moving-average.png)

Supported moving average types:
* __Simple__: An average of the last n values.
* __Weighted__: Weighted average of the last n values, where the weight decreases by 1 with each previous value.
* __Exponential__: Weighted average of the last n values, where the weight decreases exponentially with each previous value.
* __Triangular__: Weighted average of the last n values, whose result is equivalent to a double smoothed simple moving average.

## Display Options for Moving Averages
  The __MovingAverage__ class is supported like a series in FlexChart. You can choose whether or not the line displays an entry in the legend by setting the __visibility__ property to one of the following:
  * __Visible__: The series is visible on the plot and in the legend.
  * __Plot__: The series is visible only on the plot.
  * __Legend__: The series is visible only in the legend.
  * __Hidden__: The series is hidden.

  The legend text is set using the __name__ property of the series.