Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var data =[{
  2.     "probability": ".0",
  3.     "value": "0"
  4. },  {
  5.     "probability": ".10",
  6.     "value": "10"
  7. },  {
  8.     "probability": ".15",
  9.     "value": "20"
  10. },  {
  11.     "probability": ".25",
  12.     "value": "30"
  13. },  {
  14.     "probability": ".40",
  15.     "value": "40"
  16. },  {
  17.     "probability": ".60",
  18.     "value": "50"
  19. },  {
  20.     "probability": ".40",
  21.     "value": "60"
  22. },  {
  23.     "probability": ".25",
  24.     "value": "70"
  25. },  {
  26.     "probability": ".15",
  27.     "value": "80"
  28. },  {
  29.     "probability": ".10",
  30.     "value": "90"
  31. },  {
  32.     "probability": ".0",
  33.     "value": "100"
  34. }];
  35.  
  36. // var vis = d3.select("#testvis1"),
  37. //  WIDTH = 1000,
  38. //  HEIGHT = 500,
  39. //  MARGINS = {
  40. //      top: 20,
  41. //      right: 20,
  42. //      bottom: 20,
  43. //      left: 50
  44. //  };
  45.  
  46. //  var xScale = d3.scaleLinear().range([MARGINS.left, WIDTH - MARGINS.right]).domain([0, 100]);
  47. //  var yScale = d3.scaleLinear().range([HEIGHT - MARGINS.top, MARGINS.bottom]).domain([0,1]);
  48.  
  49. //  xAxis = d3.svg.axis().scale(xScale),
  50. //  yAxis = d3.svg.axis().scale(yScale);
  51.  
  52. //  vis.append("svg:g").call(xAxis);
  53. //  vis.append("svg:g").call(yAxis);
  54.  
  55. //  console.log(" We got Here");
  56.  
  57. var svg = d3.select("#testvis"),
  58.     margin = {top: 20, right: 20, bottom: 30, left: 50},
  59.     width = +svg.attr("width") - margin.left - margin.right,
  60.     height = +svg.attr("height") - margin.top - margin.bottom,
  61.     g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  62.  
  63. var parseTime = d3.timeParse("%d-%b-%y");
  64.  
  65. var x = d3.scaleTime()
  66.     .rangeRound([0, width]);
  67.  
  68. var y = d3.scaleLinear()
  69.     .rangeRound([height, 0]);
  70.  
  71. var line = d3.line()
  72.     .x(function(d) { return x(d.date); })
  73.     .y(function(d) { return y(d.close); });
  74.  
  75. d3.tsv("data.tsv", function(d) {
  76.   d.date = parseTime(d.date);
  77.   d.close = +d.close;
  78.   return d;
  79. }, function(error, data) {
  80.   if (error) throw error;
  81.  
  82.   x.domain(d3.extent(data, function(d) { return d.date; }));
  83.   y.domain(d3.extent(data, function(d) { return d.close; }));
  84.  
  85.   g.append("g")
  86.       .attr("transform", "translate(0," + height + ")")
  87.       .call(d3.axisBottom(x))
  88.     .select(".domain")
  89.       .remove();
  90.  
  91.   g.append("g")
  92.       .call(d3.axisLeft(y))
  93.     .append("text")
  94.       .attr("fill", "#000")
  95.       .attr("transform", "rotate(-90)")
  96.       .attr("y", 6)
  97.       .attr("dy", "0.71em")
  98.       .attr("text-anchor", "end")
  99.       .text("Price ($)");
  100.  
  101.   g.append("path")
  102.       .datum(data)
  103.       .attr("fill", "none")
  104.       .attr("stroke", "steelblue")
  105.       .attr("stroke-linejoin", "round")
  106.       .attr("stroke-linecap", "round")
  107.       .attr("stroke-width", 1.5)
  108.       .attr("d", line);
  109. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement