슈

동적 막대그래프

<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-06-11 조회 3,071
16-02-15 조회 3,304
16-02-02 조회 2,969
16-01-25 조회 2,584
16-01-18 조회 2,689
16-01-08 조회 2,601
16-01-07 조회 2,612
16-01-05 조회 2,650
16-01-05 조회 2,946
16-01-05 조회 2,772
16-01-05 조회 2,803
16-01-04 조회 2,664
16-01-04 조회 2,670
16-01-04 조회 2,620
16-01-04 조회 2,531
15-12-30 조회 2,886
15-12-24 조회 2,699
15-12-24 조회 2,697
15-12-24 조회 2,722
15-12-24 조회 2,678
15-12-23 조회 2,664
15-12-16 조회 2,758
15-12-15 조회 2,821
15-12-11 조회 2,946
15-12-10 조회 2,807
15-11-09 조회 2,789
15-11-09 조회 3,012
15-10-06 조회 3,349
15-10-02 조회 3,125
15-05-29 조회 4,460
15-02-02 조회 4,438
15-01-18 조회 4,416
14-10-25 조회 8,378
14-10-25 조회 5,158
14-10-22 조회 7,161
14-10-22 조회 4,865
14-10-22 조회 4,818
14-10-18 조회 5,687
14-10-17 조회 6,065
14-10-17 조회 5,442
14-10-17 조회 8,975
14-10-17 조회 6,454
14-10-13 조회 4,383
14-10-13 조회 4,478
14-10-07 조회 6,160
14-09-24 조회 3,928
14-09-23 조회 3,994
14-09-22 조회 4,897
14-09-22 조회 6,128
14-09-22 조회 4,097
14-09-22 조회 3,770
14-09-21 조회 4,381
14-09-21 조회 3,866
14-09-20 조회 3,872
14-09-20 조회 3,775
14-09-20 조회 3,953
14-09-19 조회 3,876
14-09-19 조회 4,039
14-09-19 조회 3,927
14-09-19 조회 4,312
14-09-19 조회 3,948
14-09-19 조회 3,873
14-09-19 조회 4,160
14-09-19 조회 3,893
14-09-19 조회 3,943
14-09-19 조회 3,925
14-09-18 조회 4,002
14-09-18 조회 3,960
14-09-18 조회 4,230
14-09-18 조회 4,193
14-09-18 조회 4,208
14-09-18 조회 4,906
14-09-18 조회 5,462
14-09-18 조회 5,351
14-09-18 조회 4,149
14-09-18 조회 4,643
14-09-18 조회 4,265
14-08-30 조회 5,537
14-08-06 조회 6,019
14-08-06 조회 5,634
14-08-03 조회 5,274
14-06-12 조회 5,544
14-05-11 조회 3,725
14-05-11 조회 4,485
14-05-11 조회 4,593
14-05-09 조회 1.3만
14-05-01 조회 5,188
14-03-30 조회 4,396
14-03-23 조회 8,016
14-02-12 조회 3,899
13-10-29 조회 7,859
13-10-28 조회 8,686
13-09-29 조회 6,653
13-09-29 조회 4,281
13-07-23 조회 5,158
13-07-23 조회 1.2만
13-07-14 조회 4,687
13-07-14 조회 5,077
13-07-14 조회 6,040
13-07-14 조회 5,317