I don't like constantly doing math to figure out dimensions when I'm building a dashboard of charts, so I made this helper function. It takes a matrix (array of arrays) as an argument, and divides the svg in the same manner as the matrix is divided by unique cell values.
Built with blockbuilder.org
xxxxxxxxxx
<meta charset="utf-8">
<head>
<link href='https://fonts.googleapis.com/css?family=Play' rel='stylesheet' type='text/css'>
<style>
body {
margin:auto;
font-family: 'Play', sans-serif;
font-size:100%;
}
text {
font-family: 'Play', sans-serif;
}
</style>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="matrixGrid.js"></script>
<script src="lineChart.js"></script>
<body>
<div id="dashboard"></div>
</body>
<script>
var matrix = [
[1,1,2,2,3,3,3,3],
[1,1,4,4,3,3,3,3],
[5,5,4,4,3,3,3,3]
];
var mg = matrixGrid(matrix,960,500,{top:0,left:0,bottom:0,right:0});
d3.range(1,6,1).forEach(function(d) {
mg.setCellMargin(d,20,40,40,20)
});
mg.draw("dashboard",true,false,true);
d3.range(1,6,1).forEach(function(d) {
lineChart(d)
});
</script>
https://d3js.org/d3.v4.min.js