Server-side data grouping
Since Highcharts version 7.1 it is possible to perform data grouping on the server side in a node environment. Client-side data grouping has been a part of Highcharts Stock since its beginning, but there are cases where it is beneficial to move the grouping to the server.
Server-side grouping means less data has to be pushed over the network, and less processing has to be performed in the client browser. On the downside, if the chart has to poll the server for new data every time a user zooms in or out, it may be perceived as non-performant. The Highcharts Stock lazy-loading demo, although it doesn't use our node server-side grouping, shows the concept of separate loading data for different resolutions.
Setting it up in node
An example node script can be found in test/node-datagrouping. It generates an example data set with hourly resolution, then runs two operations:
- Get the
groupPositions
. Since this is time-based data, we use theHighcharts.Time
object to find a nice distribution of ticks. ThegetTimeTicks
function takes a normalized tick interval, a minimum value, and a maximum value and generates an array of evenly distributed ticks on round dates. In the example case, all ticks land on midnights. - Group the data. The
groupData
function takes the raw X data, Y data, and thegroupPositions
, and group the data into the given positions. Y data can be two-dimensional if we're dealing with range or ohlc data. ThegroupData
function takes an argument,approximation
that dictates how the grouping should be done. The default isaverage
, but there are also options likesum
,range
orohlc
. A function can also be passed for custom approximation. Read more in the API.