Cannot figure out how to display 5 different piecharts

frank van baar's Avatar

frank van baar

20 Oct, 2015 01:44 PM

Dear Nodebox,

I'm trying to split a CSV file with 5 days and per day 3 categories to create 5 separate pietarts (so one per day) - have tried everything but cannot seem to make it work....

Hope you guys can help...

Have attached the files and a custom python script which I thought would help.

Frank

  1. 1 Posted by frank van baar on 20 Oct, 2015 01:48 PM

    frank van baar's Avatar

    And I should have added the revenant csv file of course....

  2. Support Staff 2 Posted by john on 21 Oct, 2015 09:57 AM

    john's Avatar

    Dear Frank,

    Your NodeBox file refused to open on my machine, but I got the gist of your idea. Attached is a simple NodeBox network which draws your five pie charts along with a screenshot.

    If you play with my network, rendering one node at a time, you will see how it works. The key trick is performed by subNetwork1: it sucks in one row at a time and, for each row, spits out three proportional angles which sum to 360 degrees. From there it's just a matter of using the arc node to draw each pie wedge and the grid node to arrange them into five pies.

    The grid node is a bit crafty: it's 3 columns by 5 rows but 0 pixels wide. This causes all wedges to share the same X coordinate and each trio of wedges to be drawn at the same Y coordinate; the height of the grid allows you to space out the Y coordinates for each pie to your taste. If you want to show your pies horizontally instead of vertically, just rotate the grid 90 degrees.

    I went to the extra trouble of adding pie labels from the "dag" column of your CSV and placed labels for the actual hours in the center of each pie wedge. You can adjust this to your taste.

    This would have been hard for me to do when I first started NodeBox due to the weirdness of subnetworks (which are necessary to extract the three values from each row). If you look inside it you'll see the nodes inside are quite simple. But if those nodes were not wrapped inside a subnetwork they would behave entirely differently. The subnetwork is what makes the "chunking" of one row at a time possible because it fires once for each row feeding into it.

    Hope you find this helpful. I had fun making your pies!

    John

  3. Support Staff 3 Posted by john on 21 Oct, 2015 10:04 AM

    john's Avatar

    My files failed to attach (it keeps "Processing Asset"), so I am attaching them again...

  4. Support Staff 4 Posted by john on 21 Oct, 2015 10:55 PM

    john's Avatar

    A followip...

    This solution was crafted to work with your CSV file, which assumes exactly three wedges for each of five pies. If you want a more general solution for any number of days with a different number of wedges in each pie, you should restructure your CSV file so that each row reprsents a single data point, not a single day.

    Under this scheme your current data would consist of 15 rows, each with a day (dag) column, and hours column, and whatever other columns you need (e.g. client). The first three rows would occur on day one, the next three on day two, etc.

    Once your data is in this format, things in NodeBox become more straightforward. You can use the filter node to gather all the data points for a given day. You can then do a lookup on that filtered list to retrieve the individual hour values, count them, sum them, and produce one pie chart at a time (using the group node to join the wedges into a single pie).

    This gives you a subnetwork that turns a given day into a pie chart. To create a grid or list of pies, you simply do a lookup on the day column, run it through the Distinct node to eliminate duplicates, and send that list into your pie chart subnetwork.

    John

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • mycode.py 989 Bytes
  • piechartsplit.ndbx 4.57 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

18 Oct, 2019 01:06 AM
10 Oct, 2019 01:11 AM
02 Oct, 2019 09:51 PM
30 Sep, 2019 08:21 AM
29 Sep, 2019 02:02 PM

 

03 Sep, 2019 01:35 AM
24 Aug, 2019 03:14 AM
08 Aug, 2019 04:13 AM
02 Aug, 2019 09:27 PM
18 Jul, 2019 10:05 AM
12 Jul, 2019 10:39 PM