I'm making a stream graph using d3.js for my company, and I'm wondering how to make it responsive. My code isn't much different from this example: http://bl.ocks.org/mbostock/4060954
I've been playing with setting viewBox="0 0 height width"
and preserveAspectRatio = "xMinYMid meet"
to no avail.
Any suggestions?
So, solution for this problem was this jsfiddle:
http://jsfiddle.net/shawnbot/BJLe6/ specifically, this code:
var chart = $("#chart"),
aspect = chart.width() / chart.height(),
container = chart.parent();
$(window).on("resize", function() {
var targetWidth = container.width();
chart.attr("width", targetWidth);
chart.attr("height", Math.round(targetWidth / aspect));
}).trigger("resize");
Thanks to everyone who helped!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With