This commit is contained in:
Kristofer Monisit 2012-04-07 00:17:09 +08:00
Родитель 14fe6f1f69
Коммит 0305892a96
1 изменённых файлов: 16 добавлений и 10 удалений

Просмотреть файл

@ -1,25 +1,31 @@
// Based on http://bl.ocks.org/900762 by John Firebaugh
d3.json("../data/faithful.json", function(faithful) {
data = faithful;
var w = 800,
h = 400,
x = d3.scale.linear().domain([30, 110]).range([0, w]);
var width = 800,
height = 400,
bins = d3.layout.histogram().frequency(false).bins(x.ticks(60))(data),
max = d3.max(bins, function(d) { return d.y; }),
y = d3.scale.linear().domain([0, .1]).range([0, h]),
kde = science.stats.kde().sample(data);
max = d3.max(bins, function(d) { return d.y; });
var x = d3.scale.linear()
.domain([30, 110]).range([0, width]);
var y = d3.scale.linear()
.domain([0, .1])
.range([0, height]);
var kde = science.stats.kde().sample(data);
var vis = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
.attr("width", width)
.attr("height", height);
var bars = vis.selectAll("g.bar")
.data(bins)
.enter().append("g")
.attr("class", "bar")
.attr("transform", function(d, i) {
return "translate(" + x(d.x) + "," + (h - y(d.y)) + ")";
return "translate(" + x(d.x) + "," + (height - y(d.y)) + ")";
});
bars.append("rect")
@ -29,7 +35,7 @@ d3.json("../data/faithful.json", function(faithful) {
var line = d3.svg.line()
.x(function(d) { return x(d[0]); })
.y(function(d) { return h - y(d[1]); });
.y(function(d) { return height - y(d[1]); });
vis.selectAll("path")
.data(d3.values(science.stats.bandwidth))