Highstock: DataGrouping & Approximation (average) on timestamp values

泄露秘密 提交于 2019-12-07 15:22:27

I have resolved it by modifying approximation method like below, and it seems to work fine in all cases including zoom and scrolling.

        var averageTime = this.options.data.slice(this.dataGroupInfo.start + this.cropStart, this.dataGroupInfo.start + this.cropStart + this.dataGroupInfo.length);
        var currentYear = seriesOptions[1].data.slice(this.dataGroupInfo.start + this.cropStart, this.dataGroupInfo.start + this.cropStart + this.dataGroupInfo.length)
        var len = arr.length;
        var seconds = [], cases = [];
        var finalArrayWithData = [];

        for(var i in averageTime) {
            if(averageTime[i][1] > 0) {
                var date = _format_date(averageTime[i][1], 1, 1, 1, true);
                seconds.push((((date.d * 24) * 60) * 60) + ((date.h * 60) * 60) + (date.m * 60));
                cases.push(currentYear[i][1]);
                finalArrayWithData['s'] = seconds;
                finalArrayWithData['cases'] = cases;
            }
        }
        var sumTopS = 0;
        var sumBottom = 0;

        for (var i in finalArrayWithData['cases']) {
            if(finalArrayWithData['s'][i] > 0) {
                sumTopS += finalArrayWithData['cases'][i] * finalArrayWithData['s'][i];
                sumBottom += finalArrayWithData['cases'][i];
            }
        }

        var averageS = 0;
        if ($.isNumeric(sumTopS) && sumBottom) {
            averageS = Math.round(sumTopS / sumBottom);
        }

        _dts = Date.UTC(1970, 0, 1, 0, 0, averageS) / 1000;
        return _dts;

But I still believe there must be some direct way of doing it. I have to do trick to get data from various sources. They may be available from some other easily accessible variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!