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_grayscale.html
96 lines (77 loc) · 9.62 KB
/
histogram_grayscale.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":9},{"color":1,"frequency":37},{"color":2,"frequency":75},{"color":3,"frequency":108},{"color":4,"frequency":179},{"color":5,"frequency":262},{"color":6,"frequency":311},{"color":7,"frequency":418},{"color":8,"frequency":456},{"color":9,"frequency":552},{"color":10,"frequency":643},{"color":11,"frequency":798},{"color":12,"frequency":843},{"color":13,"frequency":987},{"color":14,"frequency":1178},{"color":15,"frequency":1293},{"color":16,"frequency":1380},{"color":17,"frequency":1461},{"color":18,"frequency":1567},{"color":19,"frequency":1674},{"color":20,"frequency":1682},{"color":21,"frequency":1670},{"color":22,"frequency":1781},{"color":23,"frequency":1799},{"color":24,"frequency":1771},{"color":25,"frequency":1792},{"color":26,"frequency":1800},{"color":27,"frequency":1800},{"color":28,"frequency":1793},{"color":29,"frequency":1772},{"color":30,"frequency":1770},{"color":31,"frequency":1739},{"color":32,"frequency":1719},{"color":33,"frequency":1780},{"color":34,"frequency":1768},{"color":35,"frequency":1682},{"color":36,"frequency":1657},{"color":37,"frequency":1797},{"color":38,"frequency":1662},{"color":39,"frequency":1671},{"color":40,"frequency":1760},{"color":41,"frequency":1647},{"color":42,"frequency":1710},{"color":43,"frequency":1773},{"color":44,"frequency":1712},{"color":45,"frequency":1791},{"color":46,"frequency":1752},{"color":47,"frequency":1755},{"color":48,"frequency":1794},{"color":49,"frequency":1734},{"color":50,"frequency":1637},{"color":51,"frequency":1642},{"color":52,"frequency":1763},{"color":53,"frequency":1690},{"color":54,"frequency":1730},{"color":55,"frequency":1714},{"color":56,"frequency":1896},{"color":57,"frequency":2157},{"color":58,"frequency":2172},{"color":59,"frequency":2082},{"color":60,"frequency":2150},{"color":61,"frequency":2488},{"color":62,"frequency":3078},{"color":63,"frequency":4865},{"color":64,"frequency":6086},{"color":65,"frequency":9159},{"color":66,"frequency":11062},{"color":67,"frequency":16293},{"color":68,"frequency":17267},{"color":69,"frequency":14919},{"color":70,"frequency":13404},{"color":71,"frequency":21960},{"color":72,"frequency":19339},{"color":73,"frequency":13609},{"color":74,"frequency":11304},{"color":75,"frequency":22635},{"color":76,"frequency":17223},{"color":77,"frequency":12434},{"color":78,"frequency":14986},{"color":79,"frequency":8477},{"color":80,"frequency":10072},{"color":81,"frequency":12643},{"color":82,"frequency":14335},{"color":83,"frequency":10828},{"color":84,"frequency":9600},{"color":85,"frequency":12162},{"color":86,"frequency":16338},{"color":87,"frequency":12944},{"color":88,"frequency":9852},{"color":89,"frequency":11434},{"color":90,"frequency":11237},{"color":91,"frequency":9060},{"color":92,"frequency":12118},{"color":93,"frequency":14971},{"color":94,"frequency":8816},{"color":95,"frequency":8059},{"color":96,"frequency":9209},{"color":97,"frequency":8593},{"color":98,"frequency":8336},{"color":99,"frequency":9492},{"color":100,"frequency":9931},{"color":101,"frequency":9770},{"color":102,"frequency":9605},{"color":103,"frequency":8409},{"color":104,"frequency":10213},{"color":105,"frequency":11189},{"color":106,"frequency":9472},{"color":107,"frequency":9300},{"color":108,"frequency":10480},{"color":109,"frequency":8570},{"color":110,"frequency":9103},{"color":111,"frequency":10436},{"color":112,"frequency":9835},{"color":113,"frequency":10514},{"color":114,"frequency":10820},{"color":115,"frequency":10935},{"color":116,"frequency":11373},{"color":117,"frequency":12641},{"color":118,"frequency":12978},{"color":119,"frequency":13936},{"color":120,"frequency":15870},{"color":121,"frequency":17284},{"color":122,"frequency":19925},{"color":123,"frequency":20229},{"color":124,"frequency":20667},{"color":125,"frequency":21265},{"color":126,"frequency":22757},{"color":127,"frequency":23420},{"color":128,"frequency":22652},{"color":129,"frequency":23428},{"color":130,"frequency":21201},{"color":131,"frequency":18905},{"color":132,"frequency":18174},{"color":133,"frequency":17335},{"color":134,"frequency":16330},{"color":135,"frequency":15746},{"color":136,"frequency":15354},{"color":137,"frequency":15089},{"color":138,"frequency":14846},{"color":139,"frequency":14518},{"color":140,"frequency":14488},{"color":141,"frequency":14621},{"color":142,"frequency":14442},{"color":143,"frequency":14466},{"color":144,"frequency":14510},{"color":145,"frequency":14506},{"color":146,"frequency":13971},{"color":147,"frequency":14005},{"color":148,"frequency":13867},{"color":149,"frequency":13698},{"color":150,"frequency":13373},{"color":151,"frequency":13266},{"color":152,"frequency":13166},{"color":153,"frequency":12680},{"color":154,"frequency":12177},{"color":155,"frequency":11643},{"color":156,"frequency":11002},{"color":157,"frequency":10317},{"color":158,"frequency":9820},{"color":159,"frequency":9206},{"color":160,"frequency":8407},{"color":161,"frequency":7906},{"color":162,"frequency":7354},{"color":163,"frequency":6911},{"color":164,"frequency":6343},{"color":165,"frequency":5892},{"color":166,"frequency":5337},{"color":167,"frequency":5079},{"color":168,"frequency":4634},{"color":169,"frequency":4233},{"color":170,"frequency":4045},{"color":171,"frequency":3684},{"color":172,"frequency":3349},{"color":173,"frequency":3374},{"color":174,"frequency":3023},{"color":175,"frequency":2857},{"color":176,"frequency":2719},{"color":177,"frequency":2603},{"color":178,"frequency":2384},{"color":179,"frequency":2249},{"color":180,"frequency":2173},{"color":181,"frequency":2043},{"color":182,"frequency":1998},{"color":183,"frequency":1794},{"color":184,"frequency":1842},{"color":185,"frequency":1706},{"color":186,"frequency":1670},{"color":187,"frequency":1617},{"color":188,"frequency":1535},{"color":189,"frequency":1526},{"color":190,"frequency":1414},{"color":191,"frequency":1349},{"color":192,"frequency":1336},{"color":193,"frequency":1284},{"color":194,"frequency":1213},{"color":195,"frequency":1182},{"color":196,"frequency":1128},{"color":197,"frequency":1099},{"color":198,"frequency":1041},{"color":199,"frequency":968},{"color":200,"frequency":987},{"color":201,"frequency":916},{"color":202,"frequency":904},{"color":203,"frequency":888},{"color":204,"frequency":848},{"color":205,"frequency":800},{"color":206,"frequency":767},{"color":207,"frequency":810},{"color":208,"frequency":816},{"color":209,"frequency":814},{"color":210,"frequency":771},{"color":211,"frequency":768},{"color":212,"frequency":770},{"color":213,"frequency":771},{"color":214,"frequency":747},{"color":215,"frequency":759},{"color":216,"frequency":642},{"color":217,"frequency":636},{"color":218,"frequency":598},{"color":219,"frequency":570},{"color":220,"frequency":602},{"color":221,"frequency":646},{"color":222,"frequency":669},{"color":223,"frequency":679},{"color":224,"frequency":737},{"color":225,"frequency":782},{"color":226,"frequency":742},{"color":227,"frequency":782},{"color":228,"frequency":861},{"color":229,"frequency":926},{"color":230,"frequency":837},{"color":231,"frequency":930},{"color":232,"frequency":990},{"color":233,"frequency":1079},{"color":234,"frequency":1223},{"color":235,"frequency":1434},{"color":236,"frequency":1554},{"color":237,"frequency":1582},{"color":238,"frequency":1834},{"color":239,"frequency":1898},{"color":240,"frequency":2009},{"color":241,"frequency":1998},{"color":242,"frequency":2120},{"color":243,"frequency":2235},{"color":244,"frequency":2476},{"color":245,"frequency":2762},{"color":246,"frequency":2787},{"color":247,"frequency":3069},{"color":248,"frequency":3593},{"color":249,"frequency":3821},{"color":250,"frequency":3529},{"color":251,"frequency":3751},{"color":252,"frequency":3930},{"color":253,"frequency":4768},{"color":254,"frequency":5026},{"color":255,"frequency":1843}];
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>