This message was deleted.
# help
s
This message was deleted.
t
I had hard time to understand the data shape from observer plot website, sometimes some examples has data but sometimes they only shows a variable and I don't know how to display those data from the variable. So I decided to give chatgpt a shot, of cuz, it generated some weird incorrect code. but I want to leave it here to illustrate my question
a
Hi @tan tan! Do you these example datasets somewhere (ideally in a notebook?)
t
@Adam Roberts
Copy code
const groupLabels = ["Group 1", "Group 2", "Group 3"]; 
const dataSeries1 = [10, 20, 30]; 
const dataSeries2 = [15, 25, 35]; 
const dataSeries3 = [5, 15, 25];
I guess this is enough?
the code generated by gpt is incorrect so the sample dataset is the only useful infomation
ideally I wish I can use the array or matrix directly without creating such a
combinedData
Copy code
const groupLabels = ["Group 1", "Group 2", "Group 3"]; 
const dataset = 
[[10, 20, 30], 
[15, 25, 35], 
[5, 15, 25]];
that's the more accurate input.
the closest one I could get from the template, just need to alter the
penguins
to
dataset
https://observablehq.com/@observablehq/plot-stacked-bars?intent=fork
a
What are the factors in your desired chart? group by “Group” y axis = sum of grouped values? colors = ?
I don’t see what the stacking could be
Without stacking, it’s just basic bar chart:
t
@Adam Roberts ur right, I definitely miss some infomation about the secondary label for each item inside the group. I'm currently unable to touch my devices. Let me come back later with the correct information. If i later figure out by myself, I will also update the info and pin you so you don't get confused by me.
Fwiw, I still can leave a sample dataset here
Copy code
Group1, Group2, Group3
Tag1: [[10,   20,     30], 
Tag2: [15,    25,     35], 
Tag3: [5,     15,     25]];
Tag1,2,3
sum up to a single bar for each group, dataset is a matrix instead of an array of object
a
Ok. You can map your data to an array like this:
Copy code
const groupLabels = ["Group 1", "Group 2", "Group 3"]; 
const dataset = 
[[10, 20, 30], 
[15, 25, 35], 
[5, 15, 25]];

const datasetAsArray = groupLabels.map((label, i) => dataset[i].map(d => ({group: label, value: d}))).flat()
(I updated my example with this code …)