I am trying to make a simple line graph in D3, but have a few problems.
I want the graph to be dynamic, so when the data is updated, I would like the graph to move to the new values. Therefore, I need to use D3 transitions somewhere in my code, and I cannot find a good example of this with a line graph.
Here are the relevant parts of my code. This is not drawing anything at the moment.
var data = [ { "air_produced": 0.660985, "air_used": 0.342706, "datestr": "2012-12-01 00:00:00", "energy_used": 0.106402 } ... ]; var parseDate = d3.time.format("%Y-%m-%d %H:%M:%S"); data.forEach(function(d) { d.date = parseDate.parse(d.datestr); }); var x = d3.time.scale().range([0, width]); var y = d3.scale.linear().range([height, 0]); var line = d3.svg.line() .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.energy_used); });
JSFiddle here with the full schedule: http://jsfiddle.net/zNX8p/
Richard
source share