简体   繁体   中英

Partial Sums with DC.JS/Crossfilter

I have a data set set up with the following structure:

Q, FY, Name, Category, SubCategory, total, part1, part2, part3
q1, 2005, proj1, cat1, subcat1, 100, 25, 50, 25
q1, 2005, proj2, cat1, subcat1, 100, 25, 50, 25
q1, 2005, proj3, cat1, subcat1, 100, 25, 50, 25
q1, 2005, proj4, cat1, subcat1, 100, 25, 50, 25
q2, 2005, proj1, cat1, subcat1, 100, 25, 50, 25
q2, 2005, proj2, cat1, subcat1, 100, 25, 50, 25
q3, 2005, proj11, cat1, subcat1, 100, 25, 50, 25
q4, 2005, proj12, cat1, subcat1, 100, 25, 50, 25
q4, 2005, proj5, cat1, subcat1, 100, 25, 50, 25

I've been able to sum the totals according to the quarter within a fiscal year, and total the amounts according to the category, and was able to render this data to the graphs.

What I'm currently interested in, but having trouble with grasping, is how to loop through the part1, part2, part3 columns and obtain the sums of those columns then render them as a barchart with each column representing itself as it's own bar.. My goal is to be render a bar chart of the partial sums, then be able to adjust the totals according the filters on selected time frames or particular categories.

Any advice on how I could go about this?
Is it necessary to create a dimension for each column then sum the total according to that dimension, or is it just a matter of iterating through the columns with a loop?
ie looking to render a chart along the lines of this.. each column name is listed as an individual bar

在此处输入图片说明

Thanks in advance!

You can take a look at my response to similar question . In short, you need to format your data to look like this:

Q, FY, Name, Category, SubCategory, part
q1, 2005, proj1, cat1, subcat1, part1, 25
q1, 2005, proj2, cat1, subcat1, part2, 50
q1, 2005, proj2, cat1, subcat1, part3, 25

Here is an example: http://jsfiddle.net/jrideout/daaac/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM