Highstock Data Grouping to Use Last Data Time as I

2019-09-18 08:39发布

问题:

In Highstock (1.3.1) dataGrouping a group is indexed by using the date/time of the first data in the group.

Given we have the following 1 minute OHLC data time:

[08:59, 09:00, 09:01, 09:02, 09:03, 09:04, 09:05, 09:06, 09:07, 09:08]

Currently, if we group this into 5 minute...

  • 1st group will be [08:59] with 08:55 as index
  • 2nd group will be [09:00, 09:01, 09:02, 09:03, 09:04] with 09:00 as index
  • 3rd group will be [09:05, 09:06, 09:07, 09:08] with 09:05 as index

What I want is...

  • 1st group should be [08:59, 09:00] with 09:00 as index
  • 2nd group should be [09:01, 09:02, 09:03, 09:04, 09:05] with 09:05 as index
  • 3rd group should be [09:06, 09:07, 09:08] with 09:10 as index

I think what I want is the same with how they implemented grouping in Google Finance.

There is currently no available option in Highstock to do this. Maybe the only way to implement this is to modify a few line of codes in Highstock library. But how?

回答1:

You should be able to change this by modifying seriesProto.groupData function. There is grouping and approximation applied.

Also you can change smoothed option, so set it to true, and:

    if (dataGroupingOptions.smoothed) {
        i = groupedXData.length - 1;
        groupedXData[i] = xMax;
        while (i-- && i > 0) {
            groupedXData[i] += interval / 2; // remove '/2' -> it will create delay to group to last point
        }
        groupedXData[0] = xMin;
    }