Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. plotGraph(data){
  2. let dataset = data.map(function (item) {
  3. let color = null;
  4. let value = item.percent;
  5.  
  6. if (value > 80){
  7. color = "red";
  8. }else{
  9. color = "green";
  10. }
  11. return {"y": item.percent, "x": new Date (item.date), "color": color
  12. };
  13. });
  14. let line = d3.line()
  15. .x(function(d, i) { return graph.xScale(d.x); }) // set the x values for the line generator
  16. .y(function(d) { return graph.yScale(d.y); }) // set the y values for the line generator
  17. .curve(d3.curveMonotoneX) // apply smoothing to the line
  18. const lineGenerator = d3.line()
  19. .x(d => x(d.date))
  20. .y(d => y(d.percent))
  21. .curve(d3.curveCardinal);
  22.  
  23. graph.clearGraph();
  24. graph.svg.append("path")
  25. .data([dataset]) // 10. Binds data to the line
  26. .attr("class", "line") // Assign a class for styling
  27. .attr("d", line) // 11. Calls the line generator
  28. .attr('stroke', function(d){
  29. return d.color;});
  30. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement