2012-03-24 131 views
6

我有一個highstock折線圖,顯示給定股票的每日和每週股票價格。問題在於數據陣列足夠大時,每日數據點會「採樣」到每週數據點中,並將每週數據點採樣到每月數據點。按用戶分組爲每週,每月的數據分組

有什麼方法可以按用戶設置爲每週或每月需要時設置它們。

在此先感謝

回答

7

檢查約dataGrouping
您可以將其設置爲在需要時進行採樣,如example
或者如果你想禁用可以將其設置爲false,如代碼波紋管或here

series: [{ 
    type: 'candlestick', 
    name: 'AAPL', 
    data: arrayOfData, 
    dataGrouping: { 
     enabled: false 
    } 
}] 
-1

我們試圖解決這個黑客攻擊,在這裏我們使用Highstock的(Splinechart)RangeSelector,事件和DataGrouping。點擊每週rangeselectorButton,我們通過setExtremes捕獲此事件。發佈事件後將其近似爲「總和」。如果您使用兩個序列而不是迭代對象。

events: { 
     setExtremes: function (e) { 
      if (e.rangeSelectorButton != undefined) { 
       var triger = e.rangeSelectorButton; 
       if (triger.type == 'week') { 
        $.each(this.series, function (index, obj) { 
         obj.options.dataGrouping.units[0] = ['week', [1]]; 
        }); 
       } else if (triger.type == 'day') { 
        $.each(this.series, function (index, obj) { 
         obj.options.dataGrouping.units[0] = ['day', [1]]; 
        }); 
       } 
      } 
     } 
    }, 

@fiddle

2

您可以通過每個系列的update()方法隨時更改dataGrouping.units

//http://api.highcharts.com/highstock#plotOptions.series.dataGrouping.units 
var unit = 'week'; //'day' 'month' 

//http://api.highcharts.com/highstock#Series.update 
_chart.series.forEach(function(ser) { 
    ser.update({ 
     dataGrouping: { 
      units: [ [unit, [1]] ] 
     } 
    }, false); 
}); 

_chart.redraw(); 

實施例:http://jsfiddle.net/X5WbN/20/