슈

동적 막대그래프

<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-30 조회 2,872
16-05-11 조회 3,419
16-03-21 조회 3,170
16-03-19 조회 3,110
16-03-17 조회 2,933
16-03-17 조회 3,013
16-03-14 조회 3,028
16-03-13 조회 2,965
16-03-09 조회 3,408
16-03-08 조회 3,040
16-03-08 조회 2,848
16-03-08 조회 2,871
16-03-08 조회 3,020
16-03-07 조회 2,808
16-03-07 조회 2,800
16-02-29 조회 3,211
16-02-25 조회 3,189
16-02-22 조회 2,997
16-02-12 조회 3,294
16-02-04 조회 3,116
16-02-04 조회 3,387
16-02-04 조회 3,025
16-02-03 조회 3,183
16-02-03 조회 3,005
16-02-02 조회 2,954
16-02-02 조회 2,840
16-02-01 조회 2,849
16-01-30 조회 2,673
16-01-30 조회 2,863
16-01-30 조회 2,959
16-01-30 조회 2,781
16-01-29 조회 2,660
16-01-28 조회 2,968
16-01-28 조회 2,599
16-01-27 조회 2,563
16-01-26 조회 2,538
16-01-26 조회 2,629
16-01-25 조회 2,592
16-01-22 조회 2,571
16-01-22 조회 2,656
16-01-21 조회 2,567
16-01-19 조회 2,478
16-01-19 조회 2,517
16-01-18 조회 2,497
16-01-17 조회 2,673
16-01-14 조회 2,595
16-01-13 조회 2,782
16-01-12 조회 2,892
16-01-12 조회 2,640
16-01-11 조회 2,626
15-12-30 조회 3,212
15-12-29 조회 2,597
15-12-28 조회 2,627
15-12-09 조회 2,692
15-12-08 조회 2,898
15-12-08 조회 2,648
15-12-08 조회 2,924
15-12-07 조회 2,723
15-12-07 조회 3,104
15-12-07 조회 2,756
15-12-06 조회 2,879
15-12-06 조회 2,589
15-12-06 조회 2,829
15-12-05 조회 2,754
15-12-05 조회 3,009
15-12-05 조회 2,781
15-12-04 조회 2,647
15-12-04 조회 2,756
15-12-04 조회 2,810
15-12-03 조회 2,765
15-12-03 조회 2,796
15-12-03 조회 2,827
15-12-02 조회 2,913
15-12-02 조회 2,849
15-12-02 조회 2,996
15-12-02 조회 3,042
15-12-01 조회 2,737
15-12-01 조회 2,532
15-12-01 조회 2,608
15-11-30 조회 2,799
15-11-30 조회 2,956
15-11-30 조회 2,856
15-11-29 조회 2,624
15-11-29 조회 2,877
15-11-29 조회 2,685
15-11-28 조회 2,618
15-11-28 조회 2,648
15-11-28 조회 2,680
15-11-27 조회 2,771
15-11-27 조회 2,625
15-11-27 조회 2,639
15-11-25 조회 2,717
15-11-25 조회 2,773
15-11-25 조회 2,571
15-11-23 조회 2,838
15-11-23 조회 2,986
15-11-23 조회 2,816
15-11-21 조회 2,713
15-11-21 조회 2,608
15-11-21 조회 2,554