-
Notifications
You must be signed in to change notification settings - Fork 5
/
chart.html
105 lines (81 loc) · 2.51 KB
/
chart.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
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
html, body, #map{
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
.chart {
stroke: white;
fill: steelblue;
}
rect {
stroke : blue;
}
circle {
stroke : red;
}
</style>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function Scale(_prices, _num_buckets) {
this.raw = _prices;
this.num_buckets = _num_buckets;
this.price_buckets = [];
var max = d3.max(this.raw), min = d3.min(this.raw);
console.log("max : " + max + "min : " + min);
}
d3.json("js/all_drugs_clean.json", function (data) {
var d_id = "100";
var brand_prices = data[d_id].map(function (e) {
if (e["price"]) {
return Number(e["price"].replace(/[^0-9\.]+/g,""));
}
return 0;
});
var generic_prices = data[d_id].map(function (e) {
if (e["g_price"]) {
return Number(e["g_price"].replace(/[^0-9\.]+/g,""));
}
return 0;
});
console.log(brand_prices);
console.log(generic_prices);
brand_prices = brand_prices.sort(d3.ascending)
var chart = d3.select("body").append("svg")
.attr("class", "chart")
.attr("width", brand_prices.length)
.attr("height", brand_prices.length);
var y = d3.scale.linear()
.domain([d3.min(brand_prices), d3.max(brand_prices)])
.range([0, 500]);
var y2 = d3.scale.linear()
.domain([d3.min(generic_prices), d3.max(generic_prices)])
.range([0, 500]);
chart.selectAll("rect")
.data(brand_prices)
.enter().append("rect")
.attr("x", function (d, i) { return i; })
.attr("width", 1)
.attr("y", y.invert)
.attr("height", 2)
chart.selectAll("circle")
.data(brand_prices)
.enter().append("circle")
.attr("cx", function (d, i) { return i; })
.attr("r", 2)
.attr("cy", y2.invert);
});
</script>
</body>
</html>