-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram_g.html
96 lines (77 loc) · 9.64 KB
/
histogram_g.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":183},{"color":1,"frequency":90},{"color":2,"frequency":96},{"color":3,"frequency":94},{"color":4,"frequency":158},{"color":5,"frequency":191},{"color":6,"frequency":240},{"color":7,"frequency":295},{"color":8,"frequency":352},{"color":9,"frequency":437},{"color":10,"frequency":457},{"color":11,"frequency":589},{"color":12,"frequency":662},{"color":13,"frequency":797},{"color":14,"frequency":878},{"color":15,"frequency":971},{"color":16,"frequency":948},{"color":17,"frequency":985},{"color":18,"frequency":1104},{"color":19,"frequency":1122},{"color":20,"frequency":1154},{"color":21,"frequency":1155},{"color":22,"frequency":1180},{"color":23,"frequency":1215},{"color":24,"frequency":1250},{"color":25,"frequency":1221},{"color":26,"frequency":1282},{"color":27,"frequency":1218},{"color":28,"frequency":1229},{"color":29,"frequency":1159},{"color":30,"frequency":1227},{"color":31,"frequency":1231},{"color":32,"frequency":1118},{"color":33,"frequency":1187},{"color":34,"frequency":1162},{"color":35,"frequency":1148},{"color":36,"frequency":1155},{"color":37,"frequency":1112},{"color":38,"frequency":1087},{"color":39,"frequency":1115},{"color":40,"frequency":1119},{"color":41,"frequency":1126},{"color":42,"frequency":1095},{"color":43,"frequency":1130},{"color":44,"frequency":1258},{"color":45,"frequency":1225},{"color":46,"frequency":1451},{"color":47,"frequency":1431},{"color":48,"frequency":1499},{"color":49,"frequency":1557},{"color":50,"frequency":1882},{"color":51,"frequency":2112},{"color":52,"frequency":2386},{"color":53,"frequency":2390},{"color":54,"frequency":3247},{"color":55,"frequency":4731},{"color":56,"frequency":6915},{"color":57,"frequency":7665},{"color":58,"frequency":7739},{"color":59,"frequency":9958},{"color":60,"frequency":9266},{"color":61,"frequency":15305},{"color":62,"frequency":12966},{"color":63,"frequency":14124},{"color":64,"frequency":12820},{"color":65,"frequency":17899},{"color":66,"frequency":16301},{"color":67,"frequency":15272},{"color":68,"frequency":16098},{"color":69,"frequency":15405},{"color":70,"frequency":11899},{"color":71,"frequency":14662},{"color":72,"frequency":18038},{"color":73,"frequency":12160},{"color":74,"frequency":10795},{"color":75,"frequency":14864},{"color":76,"frequency":12455},{"color":77,"frequency":10132},{"color":78,"frequency":10085},{"color":79,"frequency":13448},{"color":80,"frequency":14614},{"color":81,"frequency":11615},{"color":82,"frequency":12715},{"color":83,"frequency":15472},{"color":84,"frequency":10427},{"color":85,"frequency":13398},{"color":86,"frequency":13085},{"color":87,"frequency":14854},{"color":88,"frequency":14115},{"color":89,"frequency":15998},{"color":90,"frequency":10988},{"color":91,"frequency":11535},{"color":92,"frequency":12366},{"color":93,"frequency":12344},{"color":94,"frequency":12587},{"color":95,"frequency":13868},{"color":96,"frequency":12311},{"color":97,"frequency":12436},{"color":98,"frequency":9649},{"color":99,"frequency":10363},{"color":100,"frequency":10216},{"color":101,"frequency":8709},{"color":102,"frequency":8672},{"color":103,"frequency":9062},{"color":104,"frequency":8063},{"color":105,"frequency":8118},{"color":106,"frequency":7735},{"color":107,"frequency":7429},{"color":108,"frequency":7152},{"color":109,"frequency":7588},{"color":110,"frequency":9104},{"color":111,"frequency":8429},{"color":112,"frequency":8721},{"color":113,"frequency":9045},{"color":114,"frequency":8607},{"color":115,"frequency":8879},{"color":116,"frequency":10441},{"color":117,"frequency":11263},{"color":118,"frequency":11204},{"color":119,"frequency":11276},{"color":120,"frequency":10490},{"color":121,"frequency":9576},{"color":122,"frequency":10167},{"color":123,"frequency":10184},{"color":124,"frequency":9919},{"color":125,"frequency":9595},{"color":126,"frequency":9759},{"color":127,"frequency":8681},{"color":128,"frequency":6957},{"color":129,"frequency":6583},{"color":130,"frequency":5500},{"color":131,"frequency":5043},{"color":132,"frequency":4726},{"color":133,"frequency":4820},{"color":134,"frequency":4685},{"color":135,"frequency":4095},{"color":136,"frequency":3716},{"color":137,"frequency":3944},{"color":138,"frequency":3414},{"color":139,"frequency":3272},{"color":140,"frequency":3226},{"color":141,"frequency":2995},{"color":142,"frequency":2861},{"color":143,"frequency":2934},{"color":144,"frequency":2946},{"color":145,"frequency":3073},{"color":146,"frequency":3097},{"color":147,"frequency":3250},{"color":148,"frequency":3392},{"color":149,"frequency":3481},{"color":150,"frequency":3592},{"color":151,"frequency":3589},{"color":152,"frequency":3815},{"color":153,"frequency":3992},{"color":154,"frequency":4254},{"color":155,"frequency":4519},{"color":156,"frequency":4713},{"color":157,"frequency":5088},{"color":158,"frequency":5395},{"color":159,"frequency":5803},{"color":160,"frequency":6140},{"color":161,"frequency":6429},{"color":162,"frequency":6741},{"color":163,"frequency":7058},{"color":164,"frequency":7404},{"color":165,"frequency":7708},{"color":166,"frequency":7979},{"color":167,"frequency":8248},{"color":168,"frequency":8659},{"color":169,"frequency":9313},{"color":170,"frequency":9806},{"color":171,"frequency":10571},{"color":172,"frequency":11473},{"color":173,"frequency":12184},{"color":174,"frequency":12636},{"color":175,"frequency":12836},{"color":176,"frequency":12904},{"color":177,"frequency":13191},{"color":178,"frequency":12962},{"color":179,"frequency":12928},{"color":180,"frequency":13097},{"color":181,"frequency":13271},{"color":182,"frequency":13457},{"color":183,"frequency":13587},{"color":184,"frequency":13553},{"color":185,"frequency":13984},{"color":186,"frequency":13886},{"color":187,"frequency":14214},{"color":188,"frequency":14113},{"color":189,"frequency":13915},{"color":190,"frequency":14032},{"color":191,"frequency":13654},{"color":192,"frequency":12942},{"color":193,"frequency":12699},{"color":194,"frequency":12162},{"color":195,"frequency":11186},{"color":196,"frequency":10625},{"color":197,"frequency":9701},{"color":198,"frequency":8795},{"color":199,"frequency":8037},{"color":200,"frequency":7310},{"color":201,"frequency":6380},{"color":202,"frequency":5575},{"color":203,"frequency":5006},{"color":204,"frequency":4628},{"color":205,"frequency":3913},{"color":206,"frequency":3560},{"color":207,"frequency":3162},{"color":208,"frequency":2858},{"color":209,"frequency":2519},{"color":210,"frequency":2287},{"color":211,"frequency":1993},{"color":212,"frequency":1898},{"color":213,"frequency":1794},{"color":214,"frequency":1710},{"color":215,"frequency":1511},{"color":216,"frequency":1409},{"color":217,"frequency":1209},{"color":218,"frequency":1104},{"color":219,"frequency":1123},{"color":220,"frequency":1042},{"color":221,"frequency":1060},{"color":222,"frequency":953},{"color":223,"frequency":1002},{"color":224,"frequency":991},{"color":225,"frequency":969},{"color":226,"frequency":976},{"color":227,"frequency":988},{"color":228,"frequency":1090},{"color":229,"frequency":1121},{"color":230,"frequency":1272},{"color":231,"frequency":1264},{"color":232,"frequency":1309},{"color":233,"frequency":1396},{"color":234,"frequency":1422},{"color":235,"frequency":1522},{"color":236,"frequency":1810},{"color":237,"frequency":1956},{"color":238,"frequency":1950},{"color":239,"frequency":1953},{"color":240,"frequency":1961},{"color":241,"frequency":2094},{"color":242,"frequency":2256},{"color":243,"frequency":2316},{"color":244,"frequency":2268},{"color":245,"frequency":2343},{"color":246,"frequency":2406},{"color":247,"frequency":2463},{"color":248,"frequency":2583},{"color":249,"frequency":2699},{"color":250,"frequency":2702},{"color":251,"frequency":2542},{"color":252,"frequency":3253},{"color":253,"frequency":4023},{"color":254,"frequency":4331},{"color":255,"frequency":8927}];
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>