2012-03-24 127 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/