Trying to create colored stacked bars

Yannis's Avatar

Yannis

09 May, 2018 06:19 PM

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

  1. Support Staff 1 Posted by john on 09 May, 2018 09:26 PM

    john's Avatar

    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. 2 Posted by Yannis on 10 May, 2018 09:39 AM

    Yannis's Avatar

    Thanks so much! This is all I needed for now. :)

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • question.zip 2.61 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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

Recent Discussions

23 Mar, 2019 09:00 PM
22 Mar, 2019 06:37 AM
17 Mar, 2019 10:13 PM
11 Mar, 2019 12:35 AM
04 Mar, 2019 03:36 AM