Search code examples
websockethighchartsreact-typescriptreact-highcharts

Highstock dataGrouping not working with live data


I am currently working on a project for my company, where I need to plot highstock charts, which show energy-data of our main buildings.

Since it is live data, new datapoints come per Websocket every few-or-so seconds. However, the graph should only show one datapoint every hour. I wanted to clear this with the highstock dataGrouping, but it does not really work. It groups the points yes, but it still shows the „transmission“, the graph-line, between them. Thus making the whole graph completely irreadable.

In an other Version of the project, the graph only shows the latest datapoint of each group (as specified in the „approximate“ object in the chart options), but also does not start a new group after the chosen Interval runs through.

I've been sitting on this problem for about 3 days now and have not found any proper completely working solution yet.

Unfortunately, due company policy and due to hooks and components necessary, which are only used here in the company, I'm not able to give you a jsfilddle or similar, even though I'd really love to. What I can do is give you the config, mabye you find something wrong there?

const options = {
    plotOptions: {
        series: {
            dataGrouping: {
                anchor: 'end',
                approximation: function (groupData: unknown[]) {
                        return groupData[groupData.length - 1];
                    },
                enabled: true,
                forced: true,
                units: [['second', [15]]],
            },
            marker: {
                enabled: false,
                radius: 2.5,
            },
            pointInterval: minutesToMilliseconds(30),
            pointStart: currentWeekTraversed?.[0]?.[0],
        },
    },
}

This would be the plotOptions.

If you need any more information, let me know. I'll see then, what and how I can send it to you.

Thank you for helping. ^^


Solution

  • This is example how dataGrouping works with live data, try to recreate your case in addition or use another demo from official Highcharts React wrapper page.

      rangeSelector: {
        allButtonsEnabled: true,
        buttons: [{
          type: 'minute',
          count: 15,
          text: '15S',
          preserveDataGrouping: true,
          dataGrouping: {
            forced: true,
            units: [
              ['second', [15]]
            ]
          }
        }, {
          type: 'hour',
          count: 1,
          text: '1M',
          preserveDataGrouping: true,
          dataGrouping: {
            forced: true,
            units: [
              ['minute', [1]]
            ]
          }
        }
      },
    

    Demo: https://jsfiddle.net/BlackLabel/sr3oLkvu/