0
votes

I have gone through the highstock datagrouping documenation(https://api.highcharts.com/highstock/series.column.dataGrouping), But little unclear about this data grouping option, Things I have noticed is, Data grouping is enabled by default in highstock, I n which we can force the datagrouping by giving custom datagrouping option through units option in datagrouping, The doubt I got is which is the default data grouping(default unit option) in highstock, another one is do we need to tell the datagrouping units for each time interval by which we are gonna show in chart(eg, if the datarange chosen is one month the grouping should by 1 day, If the daterange chosen is one day means the datagrouping units should be by hour),

units: [[
    'millisecond', // unit name
    [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
], [
    'second',
    [1, 2, 5, 10, 15, 30]
], [
    'minute',
    [1, 2, 5, 10, 15, 30]
], [
    'hour',
    [1, 2, 3, 4, 6, 8, 12]
], [
    'day',
    [1]
], [
    'week',
    [1]
], [
    'month',
    [1, 3, 6]
], [
    'year',
    null
]]

Do we need to specify each unit or do we need to change the units dynamically based on the daterange chosen?

This is what I have done, The based on the daterange the user chosen the grouping units should be changed, Do we need to specify the units based on the daterange chosen and what the units array specifies (Is Giving only one unit as option to the grouping is the functionality, Or the units array options can be chosen based on the timestamps)

Highcharts.stockChart('chart', {

      chart: {
        zoomType: false
      },

      legend: {
        enabled: true
        align: 'right',
        verticalAlign: 'top',
        x: 0,
        y: -20
      },

      navigator: {
        enabled: false
      },

      rangeSelector: {
        enabled: false
      },
    
      scrollbar: {
        enabled: false
      },

      xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: {
          day:"%b %e"
        }
      },

      yAxis: {
        opposite : false
      },
     series: [{
       data: data ,
    marker: {
      enabled: true
    },
    dataGrouping: {
      forced: true,
      approximation: "sum"
    }
  }]

EDIT While forced option is set to false enter image description here

1

1 Answers

0
votes

which is the default data grouping(default unit option) in highstock

There's a little flaw in the API (https://api.highcharts.com/highstock/series.column.dataGrouping.units) in units section. First it says that it defaults to:

units: [[
    'millisecond', // unit name
    [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
], [
    'second',
    [1, 2, 5, 10, 15, 30]
], [
    'minute',
    [1, 2, 5, 10, 15, 30]
], [
    'hour',
    [1, 2, 3, 4, 6, 8, 12]
], [
    'day',
    [1]
], [
    'week',
    [1]
], [
    'month',
    [1, 3, 6]
], [
    'year',
    null
]]

and after that "Defaults to undefined." line appears. The first one is correct.

Highcharts automatically finds the best grouping unit from units array. So, in other words: units specifies which groupings can be applied if Highcharts decides that applying data grouping is a good idea.

Enable dataGrouping.forced and use only one key-value pair in units array if you want to make sure that this grouping will be used no matter what e.g.:

units: [[
    'hour',
    [3]
] // Data will always be grouped into 3 hours periods

These're just general rules - they should be enough to use data grouping successfully.