Last active
December 22, 2016 15:28
-
-
Save said-and-done/d7f4c416fb5bf5f2ef70b27ed27514c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var draw = function(cities){ | |
| var width = $(".linechart svg"); | |
| var svg = d3.select(".linechart svg"); | |
| var width = svg.node().width.baseVal.value; | |
| var height = svg.node().height.baseVal.value; | |
| var margin = {top: 20, right: 80, bottom: 30, left: 50}, | |
| width = width - margin.left - margin.right, | |
| height = height - margin.top - margin.bottom, | |
| g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
| 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.decrement); }); | |
| x.domain([new Date(2007,0,1), new Date(2016,0,1)]); | |
| y.domain([ | |
| d3.min(cities, function(c) { return d3.min(c.series, function(d) { return d.decrement; }); }), | |
| d3.max(cities, function(c) { return d3.max(c.series, function(d) { return d.decrement; }); }) | |
| ]); | |
| var xAxis = d3.svg.axis().scale(x) | |
| .orient("bottom").ticks(5); | |
| var yAxis = d3.svg.axis().scale(y) | |
| .orient("left").ticks(5); | |
| g.append("g") | |
| .attr("class", "axis axis--x") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(xAxis); | |
| g.append("g") | |
| .attr("class", "axis axis--y") | |
| .call(yAxis) | |
| .append("text") | |
| .attr("transform", "rotate(-90)") | |
| .attr("y", 6) | |
| .attr("dy", "0.71em") | |
| .attr("fill", "#000") | |
| .text("Antal"); | |
| var city = g.selectAll(".city") | |
| .data(cities) | |
| .enter().append("g") | |
| .attr("class", "city"); | |
| city.append("path") | |
| .attr("class", "line") | |
| .attr("d", function(d) {return line(d.series); }) | |
| //.style("stroke", function(d) { return z(d.id); }); | |
| city.append("text") | |
| .datum(function(d) { return {name: d.name, value: d.series[d.series.length - 1]}; }) | |
| .attr("transform", function(d) { return "translate(" + x(d.value.date) + "," + y(d.value.decrement) + ")"; }) | |
| .attr("x", 3) | |
| .attr("dy", "0.35em") | |
| .style("font", "10px sans-serif") | |
| .text(function(d) {return d.name; }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment