Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. var width = 500,
  2. height = 500;
  3. var svg = d3.select('.main-container')
  4. .append('svg')
  5. .attr('width', 600)
  6. .attr('height', 600);
  7.  
  8. var xScale = d3.scaleBand()
  9. .range([0, width - 100])
  10. .padding(0.4),
  11. yScale = d3.scaleLinear()
  12. .range([height - 100, 0]);
  13.  
  14. g = svg.append("g").attr("transform", "translate(" + 100 + "," + 100 + ")");
  15.  
  16. xScale.domain(year);
  17.  
  18. yScale.domain([d3.min(values), d3.max(values)]);
  19.  
  20. g.append("g").attr("transform", "translate(0," + (height - 100) + ")")
  21. .call(d3.axisBottom(xScale));
  22. g.append("g").attr("transform", "translate(0,0)")
  23. .call(d3.axisLeft(yScale).ticks(8));
  24.  
  25.  
  26. **/* I need to pass the json data here to plot the corresponding path for each countries here */**
  27. g.append("path")
  28. .attr("d", -------)
  29. .attr("stroke", "blue")
  30. .attr("stroke-width", 2)
  31. .attr("fill", "none");
  32.  
  33. });
  34.  
  35.  
  36.  
  37. **json Data :**
  38.  
  39. {
  40. "22": [{
  41. "Country": "Rainfall",
  42. "2010": "10",
  43. "2011": "20",
  44. "2012": "41",
  45. "2013": "85.5",
  46. "2014": "114",
  47. "2015": "120",
  48. "2016": "130",
  49. "2017": "144.5"
  50. }, {
  51. "Country": "Tokyo",
  52. "2010": "12",
  53. "2011": "21",
  54. "2012": "42",
  55. "2013": "86.5",
  56. "2014": "115",
  57. "2015": "121",
  58. "2016": "131",
  59. "2017": "145.5"
  60. }]
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement