choropleth color domain

806 views
Skip to first unread message

Paul Katsen

unread,
Jan 26, 2014, 12:50:44 AM1/26/14
to dc-js-us...@googlegroups.com
i've seen this question around but can't find a working solution.

has anyone set a dynamic colorDomain for the choropleth chart? for example if the group going into colorDomain has min = 0, max=100 originally. then after a filter, the min = 20, max =30. how do i make sure the choropleth is updating it's color domain based on min and max of the group after each filter?

Matt Traynham

unread,
Jan 26, 2014, 1:32:22 AM1/26/14
to dc-js-us...@googlegroups.com
You can add listeners for preRender and preRedraw to handle this.  Basically, you'll want to call the color mixin's "colorDomain" function.  When you create the chart, do this:

        var chartX = new dc.geoChoroplethChart("chartX");
        chartX.on("preRender", function(chart) {
            chart.colorDomain(d3.extent(chart.data(), chart.valueAccessor()));
        });
        chartX.on("preRedraw", function(chart) {
            chart.colorDomain(d3.extent(chart.data(), chart.valueAccessor()));
        });

d3.extent(chart.data(), chart.valueAccessor()should give you the correct [min, max] values for the color domain.

Paul Katsen

unread,
Jan 26, 2014, 1:47:59 AM1/26/14
to dc-js-us...@googlegroups.com
If I could hug you I would.

Matt Traynham

unread,
Jan 26, 2014, 7:53:32 PM1/26/14
to dc-js-us...@googlegroups.com
Ha!  No problem :)

Lionel Roubeyrie

unread,
Mar 13, 2015, 11:27:23 AM3/13/15
to dc-js-us...@googlegroups.com
Hi,
with 1.7.0, we get an error saying dc.data() is not a function :/
Is there another way to dynamically change the map colors domain?

Thanks

Gordon Woodhull

unread,
Mar 13, 2015, 12:12:01 PM3/13/15
to dc.js user group
Yes, you can simply use

chart.group().all()

instead of

chart.data()



--
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/5b0c82b7-91b4-4c42-9e65-c988367cc78a%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages