Robert Andersson Robert Andersson -4 years ago 50
Javascript Question

How to update axis in a chart with dispatch events d3js

I've posted a plunker (UPDATED), a simplified version of Mike Bostocks chart where I'd like the y-axis to be dynamic.

Normaly I'd just put the

y.domain
and call the
yAxis
in a "update" function, but this doesn't work in this case, and I understand why. I'm just not sure what I should do to make the y-axis dynamic.

Is it non-dynamic because it's calcuating the max value from all the categories in the domain?

.domain([0, d3.max(stateById.values(), function(d) { return d.total; })]).nice();


What can I do so that it only calculate the selected category? (and re-calculate on change)

Answer Source

Is it non-dynamic because it's calcuating the max value from all the categories in the domain?

Yes that is correct.

What can I do so that it only calculate the selected category? (and re-calculate on change)

In statechange.bar, use d.total in domain:

y.domain([0, d.total]).nice();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download