슈

동적 막대그래프

<style>

.g_width, .g_height {width: 100%;}

.g_width td:first-child { width: 10%}

.g_width div { background-color: blue; height: 20px}

.g_height tr:first-child td {height: 300px; vertical-align: bottom}

.g_height div { background-color: blue; width: 20px}

</style>

 

<table id="graph1" class="g_width">

 <tr><td>국어</td><td></td></tr>

 <tr><td>영어</td><td></td></tr>

 <tr><td>수학</td><td></td></tr>

</table>

 

<table id="graph2" class="g_height">

 <tr><td></td><td></td><td></td></tr>

 <tr><td>국어</td><td>영어</td><td>수학</td></tr>

</table>

 

<script>

function Graph(label) {

this.obj = document.getElementById(label);

this.begin = []; this.end = []; this.div = []; this.vertexes = [];

}

 

Graph.prototype.display = function(i, way) {

var _this = this, timer= []; 

timer[i] = setInterval(function () { 

if (_this.begin[i] >= _this.end[i]) clearInterval(timer[i]);

if (way == 'w')  

_this.div[i].style.width = _this.begin[i] + '%'; 

else

_this.div[i].style.height = _this.begin[i] + '%'; 

_this.begin[i] +=1;  

}, 30);

};

 

Graph.prototype.draw = function(way) {

way == 'w' ? this.width() :this.height();

for (var i=0; i<this.vertexes.length; i++) { 

this.begin[i] = 1;

this.end[i] = this.vertexes[i];

this.display(i, way); 

}

}

 

Graph.prototype.width = function() {

for (var i=0; i<this.obj.rows.length; i++) {

var cell = this.obj.rows[i].cells[1];

this.div[i] = document.createElement('div');

cell.appendChild(this.div[i]); 

}

}

 

Graph.prototype.height = function(l) {

for (var i=0; i<this.vertexes.length; i++) {

var cell = this.obj.rows[0].cells[i];

this.div[i] = document.createElement('div');

cell.appendChild(this.div[i]);

}

}

 

var graph1 = new Graph('graph1');

graph1.vertexes = [10, 90, 40];

graph1.draw('w');

 

var graph2= new Graph('graph2');

graph2.vertexes = [50, 20, 80];

graph2.draw('h');

</script>

|

댓글 1개

댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
16-01-11 조회 2,588
16-01-11 조회 2,403
16-01-11 조회 2,619
16-01-08 조회 2,807
16-01-08 조회 2,567
16-01-07 조회 2,581
16-01-05 조회 2,638
16-01-05 조회 2,616
16-01-05 조회 2,913
16-01-05 조회 2,735
16-01-05 조회 2,771
16-01-04 조회 2,626
16-01-04 조회 2,639
16-01-04 조회 2,590
16-01-04 조회 2,497
16-01-03 조회 3,331
16-01-03 조회 2,647
16-01-03 조회 2,915
16-01-02 조회 2,849
16-01-02 조회 2,592
16-01-02 조회 2,705
16-01-02 조회 2,482
16-01-01 조회 2,777
16-01-01 조회 2,702
16-01-01 조회 2,781
15-12-31 조회 2,562
15-12-31 조회 3,270
15-12-31 조회 2,868
15-12-31 조회 2,887
15-12-31 조회 2,699
15-12-30 조회 2,641
15-12-30 조회 3,207
15-12-30 조회 2,843
15-12-30 조회 2,737
15-12-30 조회 2,650
15-12-30 조회 2,563
15-12-29 조회 2,592
15-12-29 조회 2,788
15-12-29 조회 2,891
15-12-29 조회 2,608
15-12-28 조회 2,619
15-12-28 조회 2,648
15-12-28 조회 2,679
15-12-28 조회 2,520
15-12-27 조회 3,190
15-12-27 조회 2,649
15-12-27 조회 2,552
15-12-27 조회 2,613
15-12-26 조회 2,572
15-12-26 조회 2,643
15-12-26 조회 2,659
15-12-25 조회 3,349
15-12-25 조회 2,537
15-12-25 조회 2,540
15-12-25 조회 2,495
15-12-24 조회 3,035
15-12-24 조회 2,656
15-12-24 조회 2,662
15-12-24 조회 2,685
15-12-24 조회 2,639
15-12-23 조회 2,805
15-12-23 조회 2,625
15-12-23 조회 2,496
15-12-23 조회 2,627
15-12-23 조회 2,575
15-12-22 조회 2,756
15-12-22 조회 2,617
15-12-22 조회 2,597
15-12-22 조회 2,505
15-12-21 조회 2,541
15-12-21 조회 2,574
15-12-21 조회 2,546
15-12-20 조회 2,590
15-12-20 조회 2,757
15-12-20 조회 2,531
15-12-19 조회 2,614
15-12-19 조회 2,607
15-12-19 조회 2,609
15-12-18 조회 2,912
15-12-18 조회 2,582
15-12-18 조회 2,576
15-12-18 조회 2,547
15-12-17 조회 2,617
15-12-17 조회 2,536
15-12-17 조회 2,550
15-12-17 조회 2,510
15-12-16 조회 2,527
15-12-16 조회 2,562
15-12-16 조회 2,506
15-12-16 조회 2,716
15-12-15 조회 2,854
15-12-15 조회 2,782
15-12-15 조회 2,515
15-12-15 조회 2,513
15-12-15 조회 2,506
15-12-14 조회 2,578
15-12-14 조회 2,663
15-12-14 조회 2,489
15-12-13 조회 2,452
15-12-13 조회 2,497