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 the
Highcharts.Timeobject to find a nice distribution of ticks. The
getTimeTicksfunction 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
groupDatafunction takes the raw X data, Y data, and the
groupPositions, and group the data into the given positions. Y data can be two-dimensional if we're dealing with range or ohlc data. The
groupDatafunction takes an argument,
approximationthat dictates how the grouping should be done. The default is
average, but there are also options like
ohlc. A function can also be passed for custom approximation. Read more in the API.