function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex / Visualforce Dynamic Grouped Bar Charts?

I have data (in APEX) from an AggregateResult that consists of 3 items: 'Company', 'Division', and 'Count' pulled by a SOQL query on contacts grouping by Company / Division and giving the count for each Company / Division pair that it found.

I'm looking to create a bar chart from this AggregateResult that will group bars by Company, and display each bar grouped by Company titled with Division and the bar value itself being the 'Count'. So you'll see multiple groups of Company, and then bars for the Divisions that exist for that company and counts for those bars.

I've looked at: for how to go about making grouped bar charts similar to this, but the data / grouping in all the examples I've seen so far is static, meaning that in my case for Division since I have several possible Divisions which could exist for any company (or not be there in a company at all, and therefore shouldn't be displayed), I can't make all Divisions for all companies the same and display them like division1,division2,division3 etc. for all the grouped companies -- this would need to be dynamic and the Divisions be based on what is pulled from the original query that generated the AggregateResult. Note that divisions themselves are dynamic as well and could change and the graph would have to allow for that (like a new company enters the database that has a new possible division that didn't exist before -- the graph should display that and not care about what or how many Divisions already exist in the database)

How do I go about grouping by my Companies and having the bars it shows grouped for each Company be dependent on the dynamically pulled Divisions for that company?