2017-01-15 49 views
0

啓用dataGrouping的highstock列範圍似乎不能正確計算dataAggregation。Highstock列數據分組值不一致

更改範圍時,聚合值似乎會改變。 如果向右滾動更多,2014年3月會顯示不同的值。 issue highlighted

碼和的jsfiddle:

dataGrouping: { 
      enabled: true, 
      approximation: function() { 
      const indices = _.range(this.dataGroupInfo.start, this.dataGroupInfo.start + this.dataGroupInfo.length); 
      const low = _.min(indices.map(i => this.options.data[i][1])); 
      const high = _.max(indices.map(i => this.options.data[i][2])); 

      return [low, high]; 
      }, 
      groupPixelWidth: 50 
     } 

jsfiddle

回答

1

列被改變,只有當導航器不從beggining開始 - 那是因爲你的方式定義逼近回調。

dataGroupInfo包含根據圖表中可見點(落入x軸範圍,裁剪點)的信息,而不是所有點 - 因此要有適當的初始數據索引,您需要添加this.cropStart - 它是從哪些點可見的索引。

approximation: function() { 
       const start = this.cropStart + this.dataGroupInfo.start; 
       const stop = start + this.dataGroupInfo.length; 

       const indices = _.range(start, stop); 
       const low = _.min(indices.map(i => this.options.data[i][1])); 
       const high = _.max(indices.map(i => this.options.data[i][2])); 

       return [ low, high ]; 
       }, 

例如:https://jsfiddle.net/12o4e84v/7/

同樣的功能可以實現更容易

approximation: function(low, high) { 
    return [ _.min(low), _.max(high) ]; 
} 

例如:https://jsfiddle.net/12o4e84v/8/

或者更簡單:

approximation: 'range', 

但是,默認情況下,列的近似值設置爲range,因此您不必手動執行。

示例:https://jsfiddle.net/12o4e84v/9/