Skip to content

Instantly share code, notes, and snippets.

@adicirstei
Last active September 11, 2015 07:27
Show Gist options
  • Save adicirstei/466e871af3bd7c4467d5 to your computer and use it in GitHub Desktop.
Save adicirstei/466e871af3bd7c4467d5 to your computer and use it in GitHub Desktop.
homework d3 vis
[
{"year": "1990",
"party": "Republicans",
"spending": 299
},
{"year": "1990",
"party": "Democrats",
"spending": 376
},
{"year": "2006",
"party": "Republicans",
"spending": 630
},
{"year": "2006",
"party": "Democrats",
"spending": "733"
}]
function draw(data) {
"use strict";
var margin = 75,
width = 960 - margin,
height = 500 - margin;
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin)
.attr("height", height + margin)
.append('g')
.attr('class','chart');
/*
Dimple.js Chart construction code
*/
var myChart = new dimple.chart(svg, data);
var x = myChart.addCategoryAxis("x", ["year"]);
/* x.dateParseFormat = "%Y";
x.tickFormat = "%Y";
*/
myChart.addMeasureAxis("y", "spending");
myChart.addSeries("party", dimple.plot.line);
myChart.draw();
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.0.0.min.js"></script>
<script type="text/javascript" src="draw.js">
</script>
</head>
<body>
<script type="text/javascript">
/*
Use D3 (not dimple.js) to load the TSV file
and pass the contents of it to the draw function
*/
d3.json('data.json', draw);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment