슈

동적 막대그래프

<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-03-02 조회 3,248
16-01-19 조회 2,528
15-12-23 조회 2,961
15-12-08 조회 3,678
14-10-30 조회 5,734
14-06-06 조회 5,556
12-08-30 조회 3,912
12-08-20 조회 3,831
12-07-15 조회 5,158
12-07-13 조회 3,630
12-07-06 조회 3,858
12-06-27 조회 3,368
12-06-23 조회 3,570
12-05-03 조회 5,182
12-04-20 조회 4,128
12-03-29 조회 4,634
12-03-22 조회 4,740
12-03-22 조회 3,510
12-03-21 조회 3,284
12-03-11 조회 3,715
12-03-06 조회 4,264
12-02-22 조회 4,532
12-02-17 조회 3,331
12-02-17 조회 6,180
12-02-14 조회 6,138
12-02-06 조회 4,263
12-01-18 조회 3,216
12-01-06 조회 3,444
11-12-30 조회 3,917
11-12-30 조회 7,062
11-12-21 조회 3,281
11-12-21 조회 4,247
11-12-16 조회 3,273
11-12-15 조회 3,323
11-12-15 조회 3,423
11-12-15 조회 4,224
11-12-09 조회 3,228
11-12-09 조회 3,309
11-12-07 조회 2,877
11-12-07 조회 3,962
11-12-05 조회 4,419
11-12-02 조회 3,863
11-12-01 조회 2,737
11-12-01 조회 2,780
11-12-01 조회 2,767