xxxxxxxxxx
<html>
<head>
<title>d3.js with Direct Yahoo Finance</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/d3@2.3.0/d3.js"></script>
<style type="text/css">
body {
font: 10px sans-serif;
}
rect {
fill: #ddd;
}
path.area {
fill: #000;
fill-opacity: .75;
}
.axis, .grid {
shape-rendering: crispEdges;
}
.grid line {
stroke:
#fff;
}
.grid line.minor {
stroke-opacity: .5;
}
.grid text {
display: none;
}
.axis line {
stroke: #000;
}
.grid path,
.axis path {
display: none;
}
</style>
</head>
<body>
<script type="text/javascript">
var margin = {top:
10, right: 50, bottom: 20, left: 10},
width = 960 - margin.right - margin.left,
height = 500 - margin.top -
margin.bottom,
parse = d3.time.format("%Y-%m-%d").parse;
// Scales. Note the inverted range for the y-scale
var x = d3.time.scale()
.range([20, width - 20]);
var y = d3.scale.linear()
.range([height - 20,
20]);
// Axes.
var xAxis = d3.svg.axis().scale(x).orient("bottom"),
yAxis = d3.svg.axis().scale(y).orient
("right");
// An area generator.
var area = d3.svg.area()
.x(function(d) { return x(d.Date); })
.y0(y(0))
.y1(function(d) { return y(d.Close); });
var svg = d3.select("body").append("svg")
.attr("width", width +
margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr
("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("rect")
.attr("width", width)
.attr("height", height);
//use this line if running outside of bl.ocks.org
//d3.json("https://axysreporting.com/proxy-json.php?ticker=^rut&month=1&day=1&year=1900", function(data) {
//to work in blocks I have pasted the json into this gist
d3.json("rut-json.json", function(data) {
// Parse dates and numbers.
data.reverse().forEach(function(d) {
d.Date = parse(d.Date);
d.Close = +d.Close;
});
// Compute the minimum and maximum date, and the maximum price.
x.domain([data[0].Date, data[data.length -
1].Date]);
y.domain([0, d3.max(data, function(d) { return d.Close; })]);
svg.append("g")
.attr("class", "x grid")
.attr("transform", "translate(0," + height + ")")
.call(xAxis.tickSubdivide(1).tickSize(-
height));
svg.append("g")
.attr("class", "y grid")
.attr("transform", "translate(" + width + ",0)")
.call(yAxis.tickSubdivide(1).tickSize(-width));
svg.append("g")
.attr("class", "x axis")
.attr
("transform", "translate(0," + height + ")")
.call(xAxis.tickSubdivide(0).tickSize(6));
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + width + ",0)")
.call(yAxis.tickSubdivide
(0).tickSize(6));
svg.append("path")
.attr("class", "area")
.attr("d", area(data));
});
</script>
</body>
</html>
Modified http://mbostock.github.com/d3/d3.js?2.3.0 to a secure url
https://mbostock.github.com/d3/d3.js?2.3.0