Trying to create colored stacked bars
Hi,
I am trying to create stacked bars, i.e. bars with parts of different height in different color. In the attached file there are columns for r,g,b to use for colorization, and an "area" column to define the height of each color within the column. So far, the columns (years) appear fine, but the height is calculated arbitrarily.
Yannis
- question.zip 2.61 KB
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by john on 09 May, 2018 09:26 PM
Hi Yannis,
You are making one stack per year and the segments in each year are proportional to the area value in your csv.
The basic trick is to make one stack at a time using a stack node (not a grid). You need a function which reads in a list of the all the data plus a value indicating the year of that particular stack. This function first filters the data to only rows from that year. Then, for each row, it makes a rectangle with a constant width and a height proportional to area. It then colors each rectangle and uses the stack node to stack them vertically from the bottom up (north). It will then output that stack packaged as a single group.
This function will spit out one stack for each year you feed into it. You can then use another stack node to arrange your year stacks horizontally (east) and an align node to make sure they all line up on the x axis. It is then easy to add labels for each stack.
I have created a NodeBox network that does exactly this. See zip file and screenshot. The "make_stack" function is a NodeBox subnetwork. Control click on it and choose Edit Children to open it up and see how it works.
Please let me know if this helps and don't be afraid to ask more questions!
John
2 Posted by Yannis on 10 May, 2018 09:39 AM
Thanks so much! This is all I needed for now. :)