javascript - Real time charts with D3.js -
i totally new d3.js. trying create simple sparkline time on x axis , numbers upto 1000 on y axis. have web socket server pushes random numbers unto 1000 clients. plot graph these values on y axis , time (in 24 hrs format) on x axis. tried few things, none of them work properly. graph turns out vertical , displayed sometimes.
appreciate in getting working.
below have in code, tweaked version of example found online.
data[] populated web socket call.
var margin = {top: 20, right: 20, bottom: 20, left: 40}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var x = d3.scale.linear() .domain([0, data[data.length -1]]) .range([0, width]); var y = d3.scale.linear() .domain([0, 100]) .range([height, 0]); var line = d3.svg.line() .x(function(d, i) { var dt = new date(); var time = dt.gethours() + ":" + dt.getminutes() + ":" + dt.getseconds(); return dt.getseconds(); }) .y(function(d, i) { console.log("d " + d+ "y " + y(d));return y(d); }); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); svg.append("defs").append("clippath") .attr("id", "clip") .append("rect") .attr("width", width) .attr("height", height); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + y(0) + ")") .call(d3.svg.axis().scale(x).orient("bottom")); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(0," + x(0)+")") .call(d3.svg.axis().scale(y).orient("left")); var path = svg.append("g") .attr("clip-path", "url(#clip)") .append("path") .datum(data) .attr("class", "line") .attr("d", line); redraw(); function redraw() { path .attr("d", line) .attr("transform", null) .transition() .duration(500) .ease("linear") .attr("transform", "translate(" + x(-1) + ",0)") .each("end", tick); data.shift(); }
could point me beginner's tutorial d3 me started creating different types of graphs?
it may have structure of data using.
if want go angular+d3js there few libraries out ther job done quickly.
an simple library is: http://angularjs-nvd3-directives.github.io/angularjs-nvd3-directives/
another set of directives use d3.js http://krispo.github.io/angular-nvd3/#/ home page has lot of examples can check. although lacks of documentation, every example has plunker , can check how works.
Comments
Post a Comment