score:0
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)
chart.addSeries({
name: 'Moving Average',
data: data
});
});
Example: JS Fiddle with data
score:4
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.
score:4
These days there is a plugin for Highcharts with which you can add a SMA (Simple Moving Average).
See: http://www.highcharts.com/plugin-registry/single/16/technical-indicators
score:4
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.
score:5
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.
Source: stackoverflow.com
Related Query
- how to implement moving average in highchart
- How to implement Highchart in AngularJS.i was trouble with implementation highchart in angular
- How to implement date selector to HighChart StockChart in reactjs (without jQuery)
- How to implement motion video highchart on Reactjs
- How to render Gantt Highchart from data source
- Highchart spline Cut Off when reach to maximum scale value. How can it fixed?. I have attached may sample code on body
- Highchart Android How to implement drilldown in loop
- How to implement HighChart thousandsSep() for android(JAVA) on Hi-chart WordCloud
- how to hide highchart x - axis data values
- How to display highchart series line marker symbol from tooltip formatter?
- How to change the font family of Highchart to Bootstrap css default font family
- How to export a Highchart chart to PDF thanks to a button outside the chart?
- HTML5/JS Chart with Moving Average
- How to create a new Highstock chart with new Highchart and not jquery?
- How to Load HighChart dynamically within angular UI Accorion(uib-Accordion)?
- How to set PointIntervals per month in HighChart
- How to display highchart y axis with constistant data
- How to apply borderRadius only for top side of Column or Bar in Highchart
- How to break highchart bars for extreme values
- How to know information about the clicked bar in highchart column r shiny plot
- How can I do in Highchart to have 1px space between the columns and the y Axis?
- How to draw HighChart XAxis dynamically
- How to dynamically change axis from linear to logarithmic in HighChart
- How can I generate a real-time highchart from my database data?
- How to use highstocks navigator on a highchart
- How to add a newline to a Highchart tooltip?
- How to change series legend text color in HighChart chart?
- how to reset Highchart chart width in percentage on Button click
- How to use this highchart map in reactJS
- How can I extend the lines of this Highchart series to the edges of my chart area?
More Query from same tag
- High Chart - columnrange Type depending on months
- is there any way we can append last value forcefully on x-axis?
- How do you get the extreme y-axis values in HighCharts?
- sort chart bar by color with the correct value from the text file using HIGHCHART,PHP
- Selenium: How to relate an id or a class to a specific div?
- Highcharts spline dataLabels overlapping
- Charts on rails 3 using highcharts
- Highcharts chart creation using d3.csv
- Remove 'low' label for Highcharts Range chart
- Column chart in Highcharts - select series with a click
- Messed up LineChart with highcharts
- Fixed width Font Awesome in HighCharts tooltip
- High Charts - Populating Data From Array
- Javascript not showing up in Rails 4. (Highchart)
- Highchart's selection-function updating with delay
- Highcharts - column chart has space between bar and xAxis
- Highcharts phantomjs export server can't parse json string
- How to have multiple highcharts with different series data in vuejs without repeating code
- Angular highcharts show selected bar in bar chart
- How to format Ruby array to be used as data in Highcharts
- Highchart is not working in jquery function
- How Can I show a percentage of the value on the graph?
- it is possible to style HIGHCHARTS like this?
- Show average in highcharts graph as column
- Laravel and Charting - Determine The Difference Between Datatimes
- How to change circle to rectangle when mouse hovers on the heat map charts
- highcharts-ng grows but doesn't shrink in flexbox
- Stacked Column Highchart with Angular6 is not working
- Highcharts export stops working after first export
- Bar chart - Bar padding and alignment