Sum by category in Piechart (Dc.js & Crossfilter)

I try to use dc.js and Crossfilter but I have some problem by adding values having the same category.

I explain : I have for the demo 3 columns (Project, Amount, Action). Then I create amount categories with this code:

   var amount = d.amount;
        if (amount<=10) {
            return '< 10';
        } else if (amount >10 && amount < 50) {
            return '<50';
        } else if (amount >= 50 && amount <= 80) {
            return '< 80';
        } else {
            return '> 80';
        }

All I want is : if it's the same project, add all the amount and create these categories.

So in < 10 category there is only Redaction. In the >10 and <50 category there'll be design and website hosting... And if >50 there'll be Website Design.

Here is the Jsfiddle : http://jsfiddle.net/nicart/179n4bfg/6/

Thank you for your help, I'm totally lost.

Upvotes: 0

Views: 512

Answers (2)

Greenhorn
Greenhorn

Reputation: 590

Check this out Pie Chart. .label method used.

Hope this answers your question to some extent. You may modify if it helps. Let me know :-)

Upvotes: 1

Ethan Jewett
Ethan Jewett

Reputation: 6010

So you want to dynamically calculate this category? For example, if the "Design" project had a "stuff" action with a value of 5, and a filter were applied to only show "stuff", then "Design" would fall into the "<10" category? Or do you want each project categorized according to it's overall value no matter what filters are applied?

If the former, you're going to have to create a group wrapper to create a "fake" group and re-aggregate a standard group on your Project dimension into your categorical values at run-time. See here, where it talks about creating a "fake group": https://github.com/dc-js/dc.js/wiki/FAQ

If the latter, then you should do this as a pre-calculation step and add a category dimension to your underlying data for each record.

Upvotes: 2

Related Questions