Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Grouping - Monthly (end-of-month)

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.

like image 847
Scott Avatar asked May 16 '13 19:05

Scott


People also ask

How do you group data in a month?

Right-Click on any cell within the Dates column and select Group from the fly-out list. Then select Month in the dialog box. Using the Starting at: and Ending at: fields, you can even specify the range of dates that you want to group if you don't want to group the entire list.

How do I group data by month and day in a PivotTable?

The easiest way to group by a date period is to right-click in a cell in a date field in a pivot table and select the desired grouping increments. You can group dates by quarters, years, months and days.


2 Answers

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

like image 156
rattek Avatar answered Oct 05 '22 22:10

rattek


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]];
                     });
                 }
             }
         }
     },
like image 21
imsinu9 Avatar answered Oct 06 '22 00:10

imsinu9