Skip to content

Instantly share code, notes, and snippets.

@aaronbalthaser
Last active November 14, 2017 18:19
Show Gist options
  • Save aaronbalthaser/eba1d4e9101b9a1b7800f44378762a94 to your computer and use it in GitHub Desktop.
Save aaronbalthaser/eba1d4e9101b9a1b7800f44378762a94 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.chart {
/* background: lightgray; */
border: 1px solid black;
width: 400px;
height: 600px;
}
</style>
</head>
<body>
<div class="chart"></div>
<script>
var margin = { top: 10, right: 25, bottom: 30, left: 30 };
var width = 400 - margin.left - margin.right;
var height = 600 - margin.top - margin.bottom;
var svg = d3.select('.chart')
.append('svg')
.attr('width', 425)
.attr('height', 625)
.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
svg.append('rect')
.attr('width', width / 2)
.attr('height', height)
.style('fill', 'lightblue')
.style('stroke', 'green') ;
svg.append('rect')
.attr('x', width / 2)
.attr('width', width / 2)
.attr('height', height)
.style('fill', 'lightblue')
.style('stroke', 'green');
// Y Axis
var yScale = d3.scaleLinear()
.domain([0, 100])
.range([height, 0]);
var yAxis = d3.axisLeft(yScale);
svg.call(yAxis);
// X Axis
var xScale = d3.scaleTime()
.domain([new Date(2016, 0, 1, 6), new Date(2016, 0, 1, 9)])
.range([0, width]);
var xAxis = d3.axisBottom(xScale)
.ticks(5)
svg.append('g')
.attr('transform', `translate(0, ${height})`)
.call(xAxis);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment