Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var data =[{
- "probability": ".0",
- "value": "0"
- }, {
- "probability": ".10",
- "value": "10"
- }, {
- "probability": ".15",
- "value": "20"
- }, {
- "probability": ".25",
- "value": "30"
- }, {
- "probability": ".40",
- "value": "40"
- }, {
- "probability": ".60",
- "value": "50"
- }, {
- "probability": ".40",
- "value": "60"
- }, {
- "probability": ".25",
- "value": "70"
- }, {
- "probability": ".15",
- "value": "80"
- }, {
- "probability": ".10",
- "value": "90"
- }, {
- "probability": ".0",
- "value": "100"
- }];
- // var vis = d3.select("#testvis1"),
- // WIDTH = 1000,
- // HEIGHT = 500,
- // MARGINS = {
- // top: 20,
- // right: 20,
- // bottom: 20,
- // left: 50
- // };
- // var xScale = d3.scaleLinear().range([MARGINS.left, WIDTH - MARGINS.right]).domain([0, 100]);
- // var yScale = d3.scaleLinear().range([HEIGHT - MARGINS.top, MARGINS.bottom]).domain([0,1]);
- // xAxis = d3.svg.axis().scale(xScale),
- // yAxis = d3.svg.axis().scale(yScale);
- // vis.append("svg:g").call(xAxis);
- // vis.append("svg:g").call(yAxis);
- // console.log(" We got Here");
- var svg = d3.select("#testvis"),
- margin = {top: 20, right: 20, bottom: 30, left: 50},
- width = +svg.attr("width") - margin.left - margin.right,
- height = +svg.attr("height") - margin.top - margin.bottom,
- g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
- var parseTime = d3.timeParse("%d-%b-%y");
- var x = d3.scaleTime()
- .rangeRound([0, width]);
- var y = d3.scaleLinear()
- .rangeRound([height, 0]);
- var line = d3.line()
- .x(function(d) { return x(d.date); })
- .y(function(d) { return y(d.close); });
- d3.tsv("data.tsv", function(d) {
- d.date = parseTime(d.date);
- d.close = +d.close;
- return d;
- }, function(error, data) {
- if (error) throw error;
- x.domain(d3.extent(data, function(d) { return d.date; }));
- y.domain(d3.extent(data, function(d) { return d.close; }));
- g.append("g")
- .attr("transform", "translate(0," + height + ")")
- .call(d3.axisBottom(x))
- .select(".domain")
- .remove();
- g.append("g")
- .call(d3.axisLeft(y))
- .append("text")
- .attr("fill", "#000")
- .attr("transform", "rotate(-90)")
- .attr("y", 6)
- .attr("dy", "0.71em")
- .attr("text-anchor", "end")
- .text("Price ($)");
- g.append("path")
- .datum(data)
- .attr("fill", "none")
- .attr("stroke", "steelblue")
- .attr("stroke-linejoin", "round")
- .attr("stroke-linecap", "round")
- .attr("stroke-width", 1.5)
- .attr("d", line);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement