ColumnChart comprised with an unknown number of stacked items

31 views
Skip to first unread message

Lloyd Charlier

unread,
Sep 13, 2023, 11:08:37 AM9/13/23
to Google Visualization API
I have successfully coded several stacked column charts with no problem, all having a similar structure shown in the snippet below:

arr.push(['Date', 'Item1', 'Item2', 'Item3', 'Item4', 'Item5']);
for (let i = 0; i < elementCount; i++)
{
arr.push
(
[
jsonData[i].date,
Number(jsonData[i].item1),
Number(jsonData[i].item2),
Number(jsonData[i].item3),
Number(jsonData[i].item4),
Number(jsonData[i].item5)
]
);
}
var data = new google.visualization.arrayToDataTable(arr);

When I execute the above code, I get several stacked columns (by date) where each column is comprised of several stacks representing the values associated with item1-item5 in the array. The item count is fixed and I know the name of each item to be displayed in the legend in advance (i.e. the chart has a legend showing "Item1", "Item2", ..., "Item5" as defined in my initial arr.push statement. All good...

Now I am trying to do something seemingly very similar however I do not know in advance the number or names of different items comprising any one stacked column. The items are being read from a database and for one column there may be only one "stack" item and for another there may be 5 "stack" items.

I suspect I'm overthinking things here and I welcome anyone to point out what should be obvious to me. Thanks in advance for any-and-all assistance.

Lloyd
Reply all
Reply to author
Forward
0 new messages