Data Grouping - Monthly (end-of-month)

前端 未结 2 443
醉梦人生
醉梦人生 2021-01-12 13:50

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

相关标签:
2条回答
  • 2021-01-12 14:25

    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]];
                         });
                     }
                 }
             }
         },
    
    0 讨论(0)
  • 2021-01-12 14:28

    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

    0 讨论(0)
提交回复
热议问题