슈

동적 막대그래프

· 2015-12-25 (금) 01:37:05 · 3245 · 1

<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-01-11 조회 2,272
16-01-11 조회 2,351
16-01-11 조회 2,324
16-01-08 조회 2,755
16-01-08 조회 2,491
16-01-07 조회 2,505
16-01-05 조회 2,512
16-01-05 조회 2,518
16-01-05 조회 2,822
16-01-05 조회 2,664
16-01-05 조회 2,700
16-01-04 조회 2,485
16-01-04 조회 2,587
16-01-04 조회 2,537
16-01-04 조회 2,450
16-01-03 조회 3,243
16-01-03 조회 2,591
16-01-03 조회 2,774
16-01-02 조회 2,778
16-01-02 조회 2,526
16-01-02 조회 2,630
16-01-02 조회 2,429
16-01-01 조회 2,718
16-01-01 조회 2,624
16-01-01 조회 2,645
15-12-31 조회 2,490
15-12-31 조회 3,185
15-12-31 조회 2,751
15-12-31 조회 2,782
15-12-31 조회 2,631
15-12-30 조회 2,591
15-12-30 조회 3,076
15-12-30 조회 2,761
15-12-30 조회 2,655
15-12-30 조회 2,513
15-12-30 조회 2,500
15-12-29 조회 2,532
15-12-29 조회 2,688
15-12-29 조회 2,793
15-12-29 조회 2,546
15-12-28 조회 2,567
15-12-28 조회 2,572
15-12-28 조회 2,538
15-12-28 조회 2,456
15-12-27 조회 3,137
15-12-27 조회 2,597
15-12-27 조회 2,506
15-12-27 조회 2,550
15-12-26 조회 2,522
15-12-26 조회 2,574
15-12-26 조회 2,578
15-12-25 조회 3,246
15-12-25 조회 2,489
15-12-25 조회 2,483
15-12-25 조회 2,415
15-12-24 조회 2,983
15-12-24 조회 2,585
15-12-24 조회 2,600
15-12-24 조회 2,630
15-12-24 조회 2,589
15-12-23 조회 2,737
15-12-23 조회 2,566
15-12-23 조회 2,438
15-12-23 조회 2,566
15-12-23 조회 2,516
15-12-22 조회 2,704
15-12-22 조회 2,557
15-12-22 조회 2,551
15-12-22 조회 2,459
15-12-21 조회 2,482
15-12-21 조회 2,529
15-12-21 조회 2,487
15-12-20 조회 2,538
15-12-20 조회 2,671
15-12-20 조회 2,486
15-12-19 조회 2,557
15-12-19 조회 2,544
15-12-19 조회 2,558
15-12-18 조회 2,845
15-12-18 조회 2,539
15-12-18 조회 2,519
15-12-18 조회 2,512
15-12-17 조회 2,556
15-12-17 조회 2,491
15-12-17 조회 2,491
15-12-17 조회 2,460
15-12-16 조회 2,472
15-12-16 조회 2,516
15-12-16 조회 2,454
15-12-16 조회 2,652
15-12-15 조회 2,807
15-12-15 조회 2,734
15-12-15 조회 2,466
15-12-15 조회 2,458
15-12-15 조회 2,453
15-12-14 조회 2,536
15-12-14 조회 2,609
15-12-14 조회 2,443
15-12-13 조회 2,421
15-12-13 조회 2,446