Skip to content

Instantly share code, notes, and snippets.

@chazcheadle
Created February 20, 2016 01:33
Show Gist options
  • Select an option

  • Save chazcheadle/d936b91a85b24d2ada0c to your computer and use it in GitHub Desktop.

Select an option

Save chazcheadle/d936b91a85b24d2ada0c to your computer and use it in GitHub Desktop.
D3, websockets test
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,700' rel='stylesheet' type='text/css'>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
</style>
</head>
<body>
<div id="temperature" class="temperature-pie"></div>
<div id="humidity" class="humidity-pie"></div>
<div id="pressure" class="pressure-pie"></div>
<script>
var dataset = [{"measurement":"temperature",units":"c","value":"22.31"}];
JSON.decode()
var width = 40,
height = 40,
radius = Math.min(width, height) / 2;
var dataset = [21.33, 78.77];
var color = d3.scale.ordinal()
.range(["rgba(180,0,0,.8)", "rgba(0,0,180,.8)"]);
var temperature = d3.selectAll('#temperature')
.append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + (width / 2) + ',' + (height / 2) + ')');
var arc = d3.svg.arc()
.outerRadius(radius)
.innerRadius(radius - 6);
var pie = d3.layout.pie()
.padAngle(.02)
.sort(null);
var arcs = temperature.selectAll('g.arc')
.data(pie(dataset))
.enter()
.append('g')
.attr('class', 'slice');
arcs.append("path")
.attr('d', arc)
.attr('fill', function(d, i) {
console.log(d);
return color(d.data);
})
.attr('id', function(d, i) { return 'slice-' + i;});
temperature.append("text")
.text(data.units)
.attr('y', 5)
.attr("text-anchor", "middle")
.style('fill', 'rgba(255,255,255,.50)');
temperature.append("circle")
.attr('cx', 0)
.attr('cy', 0)
.attr('r', 12)
.style('fill', 'rgba(255,255,255,.3)');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment