슈

동적 막대그래프

<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-07-13 조회 2,164
16-07-12 조회 2,345
16-07-12 조회 2,376
16-07-11 조회 2,192
16-06-05 조회 2,912
16-06-03 조회 3,029
16-05-26 조회 2,953
15-09-22 조회 4,985
15-06-10 조회 4,830
14-10-25 조회 6,356
14-10-22 조회 8,980
14-09-21 조회 5,788
14-09-16 조회 5,071
14-08-22 조회 1.1만
14-08-13 조회 5,903
14-08-12 조회 5,438
14-08-12 조회 6,298
14-08-11 조회 6,924
14-06-12 조회 6,199
14-06-11 조회 5,105
14-05-09 조회 5,418
14-05-09 조회 6,383
14-05-09 조회 6,410
14-05-08 조회 5,746
14-04-17 조회 4,742
14-04-16 조회 4,580
14-04-15 조회 4,585
14-04-15 조회 4,533
14-04-15 조회 4,303
14-04-14 조회 4,287
14-04-14 조회 4,255
14-04-14 조회 4,630
14-04-14 조회 4,777
14-04-14 조회 4,760
14-04-13 조회 4,663
14-04-12 조회 4,231
14-04-12 조회 4,372
14-04-12 조회 4,479
14-04-11 조회 5,007
14-04-10 조회 4,739
14-04-10 조회 4,776
14-04-09 조회 4,934
14-04-09 조회 5,302
14-04-08 조회 6,968
13-10-30 조회 7,652
13-07-11 조회 5,134
13-03-28 조회 1.1만
13-02-27 조회 6,786
13-02-14 조회 5,605
13-01-10 조회 4,521
12-12-31 조회 5,102
12-12-20 조회 6,115
12-12-12 조회 5,271
12-12-07 조회 4,496
12-11-28 조회 4,849
12-11-22 조회 5,284
12-11-12 조회 5,650
12-09-22 조회 4,510
12-09-18 조회 4,700