Data Grouping - Monthly (end-of-month)

2019-02-17 07:17发布

I'm having a very difficult time trying to get my data to be grouped via month. I've even gone so far as to programmatically filter through my data to return only the last day of the month and calculate the monthly value. I've tried to find a good explanation on the 'dataGrouping' property but have had no luck understanding it nor properly implementing it. Every results returns my series in a daily interval.

My questions are as follows:

  1. Is there a minimum number of data points needed for data grouping to work?
  2. Under the dataGrouping.units I've tried to use this documentation but nothing has worked for me - Still results in a daily interval - Could someone explain this for me?

Any help on this would be GREATLY appreciated.

2条回答
男人必须洒脱
2楼-- · 2019-02-17 07:36

We tried a Hack around this, where we used Highstock's (Splinechart) RangeSelector, Event and DataGrouping. On click of weekly rangeselectorButton we catch this event through setExtremes. Post catching the event approximate it to "sum". If you are using two series than iterate the object. Currently doing it weekly just extend it for Monthly using corresponding UNIT

  events: {
         setExtremes: function (e) {
             if (e.rangeSelectorButton != undefined) {
                 var triger = e.rangeSelectorButton;
                 if (triger.type == 'week') {
                     $.each(this.series, function (index, obj) {
                         obj.options.dataGrouping.units[0] = ['week', [1]];
                     });
                 } else if (triger.type == 'day') {
                     $.each(this.series, function (index, obj) {
                         obj.options.dataGrouping.units[0] = ['day', [1]];
                     });
                 }
             }
         }
     },
查看更多
够拽才男人
3楼-- · 2019-02-17 07:44

Are you using HighStock graph?

If yes...

Sure, it takes a lot of data to get grouping. If datagrouping option is enabled, Highstock handle automatically the switch between every grouping mode. So if you don't have a lot of data, it will not work with default settings

So, if you want to group by default, you need to force the grouping.

series:[{
    [...]
        dataGrouping: {
            approximation: "sum",
            enabled: true,
            forced: true,
            units: [['month',[1]]]

        }
}]

EDIT

Here is a working example demo (fork of a basic highstock demo) http://jsfiddle.net/NcNvu/

Hope it helps! Regards

查看更多
登录 后发表回答