I use the following link to create a funnel diagram with D3:
jakezatecky / d3-funnel
The code is working fine. Now, as the tutorial says, I want the heights of the blocks to be proportional to their weight, so I need to change the D3 deafult:
D3Funnel.defaults.block.dynamicHeight = true;
but when I add the tihs line to my code, the whole graph will disappear.
Could you help me deal with the problem? code:
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://cdn.rawgit.com/jakezatecky/d3-funnel/0.3.2/d3-funnel.js?1"></script>
<input class="btn btn-primary" type="submit" id="submit_btn" value="Create Chart">
<br><br>
<div id="funnelPanel">
<div id="funnelContainer">
<div id="funnel"></div>
</div>
</div>
<script>
var data = [
["Clicked", "5,000"],
["Joined", "2,500"],
["Shared", "50"]
];
width = $('#funnelPanel').width();
var options = {
width: width - 300,
height: 400,
bottomPct: 1 / 4,
dynamicHeight: true,
fillType: "solid",
hoverEffects: true
};
D3Funnel.defaults.block.dynamicHeight = true;
var funnel = new D3Funnel(data, options);
funnel.draw("#funnelContainer");
$(window).on("resize", function () {
var width = $("#funnelPanel").width();
options.width = width;
var funnel = new D3Funnel(data, options);
funnel.draw('#funnelContainer');
});
$('#submit_btn').on('click', function () {
var changed_data = [
["clicked", "3000"],
["joined", "70"],
["shared", "10"]
];
var funnel = new D3Funnel(changed_data, options);
funnel.draw('#funnelContainer');
});
</script>
source
share