Grouping and summating data using highcharts, without grouping the datatable

Grouping and summating data using highcharts, without grouping the datatable

cpshartcpshart Posts: 246Questions: 49Answers: 5

Hi, Is there a way to group and summate values using highcharts for a datatable showing the detailed lines.

as shown in the following example.
https://wpdatatables.com/documentation/wpdatacharts/grouping-in-charts/

I have created a datatable and an associated highchart, no problems, and I can provide extracts of the code, but the chart plots every row datapoint of data in the datatable.

so in the example above

Name . Apple
George . 2
George . 4
George . 2

In my bar chart is displayed as 3 bars with values, 2, 4, 2, but I need one bar for George, value 2+4+2 i.e 8, but I need the 3 detailed lines in the datatable.

I could add GROUP to my SQL statement, which would group the chart, but I would lose the detailed lines in my datatable.

I hope this makes sense.

Thanks

Colin

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948
    Answer ✓

    This isn't something Datatables will do automatically for you. IIRC, you are looping through the rows to create your data points for the charts and simply making an array of objects. I might not be remembering this correctly. You would use the same technique but for each unique Name column create an object with the summed values. Basically you just need to create a data structure that can be graphed the way you want with Highcharts.

    Kevin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi Kevin

    Thanks for the information, understood, I will give this a go tomorrow. I assume there is no example of this being done ? otherwise I should be able to work it out.

    Thanks

    Colin

This discussion has been closed.