Ordering pie chart slices based on Month

19 views
Skip to first unread message

SMJ

unread,
Apr 23, 2017, 5:46:53 PM4/23/17
to dc-js user group
Hi All,

I would like to order the slices of the pie chart by the month order ( it is now ordering alphabetically).
Please let me know how to go about it.
Below is my code:



var monthPosted = ndx.dimension(function(d) { 
var format=d3.time.format("%b");
    var dateConvert = format(new Date(d.date));

    return dateConvert;
    });
var reviewsByMon = monthPosted.group();
    monthPieChart
        .dimension(monthPosted)
        .group(reviewsByMon)
        //.width(200)
        .height(200)
        .innerRadius(50)

Gordon Woodhull

unread,
Apr 23, 2017, 5:57:48 PM4/23/17
to dc-js-us...@googlegroups.com
I'd suggest making your group keys be the numbers of months and then mapping them to month names in chart.label:

You could also do something with chart.ordering, but that would be more complicated:

Please note, in dc.js 2.0.* and below, there is a weird interaction between crossfilter's group.order and chart.ordering, so if you're using capping they had better agree. As of 2.1.*, group.order is not used, just chart.ordering.
--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/db09cd6d-7d9c-4097-82ea-fcd27c1ba4ef%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages