D3.js is a powerful Javascript library that allows you to build SVG images and animations, implemented with HTML5 and CSS.
But don’t let that scare you. You’re awesome! You can do it!
Visualizing your Data
But perhaps you just want to whip up something on an ad-hoc basis. D3.js is superb at this. With simply a CSV file and a web server (even something as simple as "
python -m SimpleHTTPServer 8000", see William Bowers' list) you can create something that works on any modern browser, mobile included.Data Type and Format
Fundamentals of D3.js
Simple Example
First, include D3 in our HTML file,date servers 2013-12-08 4343 2013-12-07 4328 2013-12-06 4325
Now create the SVG.<script src="http://d3js.org/d3.vs.js"></script>
Time to load our data.var svg = d3.select("body").append("svg") .attr("width", 860) .attr("height", 500) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
And draw it.d3.tsv("vmcount.tsv", function(error, data) { data.forEach(function(d) { d.date = parseDate(d.date); d.servers = +d.servers; });
svg.append("path") .datum(data) .attr("class", "line") .attr("d", line);
The
.append("g") and attr("d", line) are not magic. They are SVG element tags. The "g" attribute indicates "group everything together as one". The "d" attribute defines a path to follow. The 3 bits of Javascript above are the core of the work, but they alone are insufficient. There is a bit more required to bring it to life and make it look nice. That includes defining axes, scales, labels and domains (in the geometric sense). The full working example can be found here. It adds all the features mentioned above, plus a fancy hover to show precise values.On Your Way
Resources:
- Interactive Data Visualization for the Web by Scott Murray (@alignedleft).
- D3.js Data Visualization Fundamentals by Ben Sullins (@bensullins).