启用了 dataGrouping 的 highstock 列范围似乎无法正确计算 dataAggregation。
更改范围时聚合值似乎会发生变化。 如果向右滚动更多,2014 年 3 月将显示不同的值。
代码和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
最佳答案
只有当导航器没有从头开始时,列才会更改 - 这是因为您定义近似回调的方式。
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',
但是,默认情况下列的近似值设置为范围
,因此您不必手动执行此操作。
关于javascript - Highstock 列范围数据分组值不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41656514/