-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbar.php
More file actions
64 lines (56 loc) · 1.86 KB
/
bar.php
File metadata and controls
64 lines (56 loc) · 1.86 KB
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
<div id="chart"></div>
<style>
.fig {
font-family:Arial;
font-size:9pt;
color:darkgray;
}
</style>
<script type="text/javascript">
var data = <?php echo $data; ?>;
var count = <?php echo $count; ?>;
var mySVG = d3.select("#chart")
.append("svg")
// .attr("viewBox", "0 0 500 500");
.attr("width", 30 * count)
.attr("height", 650)
.style('position','center')
.style('top',50)
.style('left',0)
.attr('class','fig');
var heightScale = d3.scale.linear()
.domain([0, d3.max(data,function(d) { return d.value;})])
.range([0, 400]);
mySVG.selectAll(".xLabel")
.data(data)
.enter().append("svg:text")
.attr("x", function(d,i) {return 113 + (i * 22);})
.attr("y", 435)
.attr("text-anchor", "end")
.text(function(d,i) {return d.data;})
.attr('transform',function(d,i) {return 'rotate(-90,' + (113 + (i * 22)) + ',435)';});
mySVG.selectAll(".yLabel")
.data(heightScale.ticks(10))
.enter().append("svg:text")
.attr('x',80)
.attr('y',function(d) {return 400 - heightScale(d);})
.attr("text-anchor", "end")
.text(function(d) {return d;});
mySVG.selectAll(".yTicks")
.data(heightScale.ticks(10))
.enter().append("svg:line")
.attr('x1','90')
.attr('y1',function(d) {return 400 - heightScale(d);})
.attr('x2',((28 * count) - 60))
.attr('y2',function(d) {return 400 - heightScale(d);})
.style('stroke','lightgray');
var myBars = mySVG.selectAll('rect')
.data(data)
.enter()
.append('svg:rect')
.attr('width',20)
.attr('height',function(d,i) {return heightScale(d.value);})
.attr('x',function(d,i) {return (i * 22) + 100;})
.attr('y',function(d,i) {return 400 - heightScale(d.value);})
.style('fill','lightblue');
</script>