슈

동적 막대그래프

<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,187건
+
제목 글쓴이 날짜 조회
16-02-06 조회 3,637
16-02-04 조회 3,198
16-02-04 조회 3,489
16-02-04 조회 3,142
16-02-03 조회 3,254
16-02-03 조회 3,005
16-02-03 조회 3,051
16-02-03 조회 2,966
16-02-03 조회 3,080
16-02-02 조회 3,116
16-02-02 조회 3,015
16-02-02 조회 3,039
16-02-02 조회 2,925
16-02-02 조회 3,335
16-02-01 조회 2,923
16-02-01 조회 2,731
16-02-01 조회 2,710
16-01-31 조회 2,736
16-01-31 조회 2,748
16-01-31 조회 2,748
16-01-30 조회 3,152
16-01-30 조회 2,751
16-01-30 조회 2,731
16-01-30 조회 2,926
16-01-30 조회 3,070
16-01-30 조회 2,867
16-01-29 조회 2,732
16-01-29 조회 2,735
16-01-29 조회 2,624
16-01-29 조회 2,610
16-01-28 조회 3,095
16-01-28 조회 2,945
16-01-28 조회 2,559
16-01-28 조회 2,465
16-01-28 조회 2,714
16-01-27 조회 2,644
16-01-27 조회 2,635
16-01-27 조회 2,633
16-01-26 조회 2,629
16-01-26 조회 2,605
16-01-26 조회 2,622
16-01-26 조회 2,924
16-01-25 조회 2,629
16-01-25 조회 2,676
16-01-25 조회 2,684
16-01-25 조회 2,557
16-01-24 조회 2,550
16-01-24 조회 2,551
16-01-24 조회 2,467
16-01-23 조회 2,517
16-01-23 조회 2,528
16-01-23 조회 2,504
16-01-22 조회 2,646
16-01-22 조회 2,759
16-01-22 조회 2,662
16-01-22 조회 2,743
16-01-21 조회 2,769
16-01-21 조회 2,650
16-01-21 조회 2,635
16-01-21 조회 2,639
16-01-21 조회 2,595
16-01-20 조회 2,638
16-01-20 조회 2,562
16-01-20 조회 2,513
16-01-20 조회 2,714
16-01-19 조회 2,538
16-01-19 조회 2,577
16-01-19 조회 2,564
16-01-19 조회 2,595
16-01-19 조회 2,790
16-01-18 조회 2,577
16-01-18 조회 2,566
16-01-18 조회 2,580
16-01-18 조회 2,727
16-01-17 조회 2,755
16-01-17 조회 2,608
16-01-17 조회 2,677
16-01-16 조회 2,515
16-01-16 조회 2,449
16-01-16 조회 2,509
16-01-15 조회 2,660
16-01-15 조회 2,661
16-01-15 조회 2,583
16-01-15 조회 2,513
16-01-14 조회 2,677
16-01-14 조회 2,818
16-01-14 조회 3,260
16-01-14 조회 2,567
16-01-14 조회 2,795
16-01-14 조회 2,598
16-01-13 조회 3,041
16-01-13 조회 2,658
16-01-13 조회 2,625
16-01-13 조회 2,654
16-01-13 조회 2,538
16-01-12 조회 2,960
16-01-12 조회 2,708
16-01-12 조회 2,722
16-01-12 조회 2,650
16-01-11 조회 2,774