This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram_b.html
96 lines (77 loc) · 9.59 KB
/
histogram_b.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.bar {
fill: steelblue;
}
.bar:hover {
fill: brown;
}
.axis {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .0);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var data = [{"color":0,"frequency":3412},{"color":1,"frequency":479},{"color":2,"frequency":539},{"color":3,"frequency":549},{"color":4,"frequency":641},{"color":5,"frequency":707},{"color":6,"frequency":794},{"color":7,"frequency":810},{"color":8,"frequency":843},{"color":9,"frequency":1001},{"color":10,"frequency":1043},{"color":11,"frequency":1156},{"color":12,"frequency":1192},{"color":13,"frequency":1310},{"color":14,"frequency":1428},{"color":15,"frequency":1465},{"color":16,"frequency":1625},{"color":17,"frequency":1694},{"color":18,"frequency":1766},{"color":19,"frequency":1887},{"color":20,"frequency":1949},{"color":21,"frequency":2069},{"color":22,"frequency":2207},{"color":23,"frequency":2222},{"color":24,"frequency":2238},{"color":25,"frequency":2335},{"color":26,"frequency":2465},{"color":27,"frequency":2435},{"color":28,"frequency":2513},{"color":29,"frequency":2473},{"color":30,"frequency":2447},{"color":31,"frequency":2568},{"color":32,"frequency":2578},{"color":33,"frequency":2456},{"color":34,"frequency":2459},{"color":35,"frequency":2422},{"color":36,"frequency":2397},{"color":37,"frequency":2308},{"color":38,"frequency":2267},{"color":39,"frequency":2172},{"color":40,"frequency":2133},{"color":41,"frequency":2026},{"color":42,"frequency":1973},{"color":43,"frequency":1930},{"color":44,"frequency":1886},{"color":45,"frequency":1777},{"color":46,"frequency":1690},{"color":47,"frequency":1623},{"color":48,"frequency":1554},{"color":49,"frequency":1498},{"color":50,"frequency":1412},{"color":51,"frequency":1400},{"color":52,"frequency":1358},{"color":53,"frequency":1233},{"color":54,"frequency":1205},{"color":55,"frequency":1186},{"color":56,"frequency":1157},{"color":57,"frequency":1105},{"color":58,"frequency":1055},{"color":59,"frequency":971},{"color":60,"frequency":904},{"color":61,"frequency":889},{"color":62,"frequency":931},{"color":63,"frequency":844},{"color":64,"frequency":850},{"color":65,"frequency":823},{"color":66,"frequency":773},{"color":67,"frequency":733},{"color":68,"frequency":795},{"color":69,"frequency":722},{"color":70,"frequency":668},{"color":71,"frequency":651},{"color":72,"frequency":603},{"color":73,"frequency":632},{"color":74,"frequency":626},{"color":75,"frequency":595},{"color":76,"frequency":598},{"color":77,"frequency":559},{"color":78,"frequency":569},{"color":79,"frequency":566},{"color":80,"frequency":547},{"color":81,"frequency":542},{"color":82,"frequency":558},{"color":83,"frequency":542},{"color":84,"frequency":574},{"color":85,"frequency":515},{"color":86,"frequency":596},{"color":87,"frequency":523},{"color":88,"frequency":484},{"color":89,"frequency":530},{"color":90,"frequency":574},{"color":91,"frequency":565},{"color":92,"frequency":546},{"color":93,"frequency":548},{"color":94,"frequency":576},{"color":95,"frequency":544},{"color":96,"frequency":593},{"color":97,"frequency":554},{"color":98,"frequency":624},{"color":99,"frequency":658},{"color":100,"frequency":692},{"color":101,"frequency":688},{"color":102,"frequency":708},{"color":103,"frequency":730},{"color":104,"frequency":812},{"color":105,"frequency":780},{"color":106,"frequency":786},{"color":107,"frequency":876},{"color":108,"frequency":845},{"color":109,"frequency":895},{"color":110,"frequency":926},{"color":111,"frequency":915},{"color":112,"frequency":1013},{"color":113,"frequency":1027},{"color":114,"frequency":1014},{"color":115,"frequency":1024},{"color":116,"frequency":1055},{"color":117,"frequency":1015},{"color":118,"frequency":1071},{"color":119,"frequency":1122},{"color":120,"frequency":1084},{"color":121,"frequency":1131},{"color":122,"frequency":1150},{"color":123,"frequency":1221},{"color":124,"frequency":1475},{"color":125,"frequency":1478},{"color":126,"frequency":1474},{"color":127,"frequency":1519},{"color":128,"frequency":1727},{"color":129,"frequency":1603},{"color":130,"frequency":1628},{"color":131,"frequency":1842},{"color":132,"frequency":2241},{"color":133,"frequency":2325},{"color":134,"frequency":2413},{"color":135,"frequency":3290},{"color":136,"frequency":3746},{"color":137,"frequency":4260},{"color":138,"frequency":7520},{"color":139,"frequency":8725},{"color":140,"frequency":11837},{"color":141,"frequency":12419},{"color":142,"frequency":12616},{"color":143,"frequency":8774},{"color":144,"frequency":9641},{"color":145,"frequency":10986},{"color":146,"frequency":8315},{"color":147,"frequency":8161},{"color":148,"frequency":7799},{"color":149,"frequency":16821},{"color":150,"frequency":14266},{"color":151,"frequency":11589},{"color":152,"frequency":8339},{"color":153,"frequency":8286},{"color":154,"frequency":12598},{"color":155,"frequency":13175},{"color":156,"frequency":11037},{"color":157,"frequency":7563},{"color":158,"frequency":7894},{"color":159,"frequency":10039},{"color":160,"frequency":9158},{"color":161,"frequency":5085},{"color":162,"frequency":9635},{"color":163,"frequency":5468},{"color":164,"frequency":6300},{"color":165,"frequency":5497},{"color":166,"frequency":4956},{"color":167,"frequency":7617},{"color":168,"frequency":9973},{"color":169,"frequency":11038},{"color":170,"frequency":14291},{"color":171,"frequency":11331},{"color":172,"frequency":8741},{"color":173,"frequency":7083},{"color":174,"frequency":7344},{"color":175,"frequency":7868},{"color":176,"frequency":6769},{"color":177,"frequency":12485},{"color":178,"frequency":7094},{"color":179,"frequency":8814},{"color":180,"frequency":8623},{"color":181,"frequency":9822},{"color":182,"frequency":9215},{"color":183,"frequency":8017},{"color":184,"frequency":6789},{"color":185,"frequency":9872},{"color":186,"frequency":7123},{"color":187,"frequency":7290},{"color":188,"frequency":7947},{"color":189,"frequency":7972},{"color":190,"frequency":7761},{"color":191,"frequency":7751},{"color":192,"frequency":14119},{"color":193,"frequency":13850},{"color":194,"frequency":9480},{"color":195,"frequency":9454},{"color":196,"frequency":9790},{"color":197,"frequency":9710},{"color":198,"frequency":9892},{"color":199,"frequency":10971},{"color":200,"frequency":11185},{"color":201,"frequency":10893},{"color":202,"frequency":13694},{"color":203,"frequency":13802},{"color":204,"frequency":15779},{"color":205,"frequency":18148},{"color":206,"frequency":18335},{"color":207,"frequency":20365},{"color":208,"frequency":20862},{"color":209,"frequency":20192},{"color":210,"frequency":21405},{"color":211,"frequency":21696},{"color":212,"frequency":23260},{"color":213,"frequency":26521},{"color":214,"frequency":26146},{"color":215,"frequency":27205},{"color":216,"frequency":28092},{"color":217,"frequency":26352},{"color":218,"frequency":25239},{"color":219,"frequency":26908},{"color":220,"frequency":26228},{"color":221,"frequency":27044},{"color":222,"frequency":27263},{"color":223,"frequency":25739},{"color":224,"frequency":23528},{"color":225,"frequency":24349},{"color":226,"frequency":23292},{"color":227,"frequency":22262},{"color":228,"frequency":22633},{"color":229,"frequency":20954},{"color":230,"frequency":19032},{"color":231,"frequency":17965},{"color":232,"frequency":16415},{"color":233,"frequency":15063},{"color":234,"frequency":14046},{"color":235,"frequency":12087},{"color":236,"frequency":9440},{"color":237,"frequency":8031},{"color":238,"frequency":6441},{"color":239,"frequency":5486},{"color":240,"frequency":5042},{"color":241,"frequency":4749},{"color":242,"frequency":4387},{"color":243,"frequency":4123},{"color":244,"frequency":4082},{"color":245,"frequency":3837},{"color":246,"frequency":3308},{"color":247,"frequency":3089},{"color":248,"frequency":3397},{"color":249,"frequency":2934},{"color":250,"frequency":2788},{"color":251,"frequency":2125},{"color":252,"frequency":2126},{"color":253,"frequency":4298},{"color":254,"frequency":1010},{"color":255,"frequency":4315}];
x.domain(data.map(function(d) { return d.color; }));
y.domain([0, d3.max(data, function(d) { return d.frequency; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "begin")
.text("Color value");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Frequency");
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.color); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency); });
function type(d) {
d.frequency = +d.frequency;
return d;
}
</script>