Guest User

Untitled

a guest
Jan 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. var margin = {top: 20, right: 20, bottom: 30, left: 150};
  2. var width = 800, height =200;
  3.  
  4. var svg = d3.select("svg")
  5. .append("g")
  6. .attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")");
  7.  
  8. var x = d3.scaleTime().range([0, this.width]);
  9. var y = d3.scaleLinear().range([this.height, 0]);
  10. x.domain(d3.extent(dataset, (d) => d.date ));
  11. y.domain([0, d3.max(dataset, function(d) { return d.value; })]);
  12.  
  13. var line = d3.line()
  14. .x( (d: any) => x(d.date) )
  15. .y( (d: any) => y(d.value) );
  16.  
  17. var update = this.svg
  18. .datum(dataset);
  19.  
  20. update
  21. .append("path")
  22. .merge(update)
  23. .attr("class", "line")
  24. .attr("fill", "none")
  25. .attr("stroke", "steelblue")
  26. .attr("stroke-linejoin", "round")
  27. .attr("stroke-linecap", "round")
  28. .attr("stroke-width", 1.5)
  29. .attr("class", "line")
  30. .attr("d", line);
  31.  
  32. update.exit().remove();
  33.  
  34. var update = this.svg
  35. .datum(dataset);
  36.  
  37. update.enter()
  38. .append("path")
  39. .merge(update)
  40. .attr("class", "line")
  41. .attr("fill", "none")
  42. .attr("stroke", "steelblue")
  43. .attr("stroke-linejoin", "round")
  44. .attr("stroke-linecap", "round")
  45. .attr("stroke-width", 1.5)
  46. .attr("class", "line")
  47. .attr("d", this.line);
  48.  
  49. var update = this.svg
  50. .selectAll("path")
  51. .datum(dataset);
  52.  
  53. update.enter()
  54. .append("path")
  55. .merge(update)
  56. .attr("class", "line")
  57. .attr("fill", "none")
  58. .attr("stroke", "steelblue")
  59. .attr("stroke-linejoin", "round")
  60. .attr("stroke-linecap", "round")
  61. .attr("stroke-width", 1.5)
  62. .attr("class", "line")
  63. .attr("d", this.line);
Add Comment
Please, Sign In to add comment