2017-01-15 46 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/