슈

동적 막대그래프

· 2015-12-25 (금) 01:37:05 · 3294 · 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-05-11 조회 3,026
16-03-11 조회 2,835
16-03-09 조회 2,902
16-02-18 조회 3,049
16-01-28 조회 2,562
16-01-26 조회 2,483
16-01-22 조회 2,511
16-01-21 조회 2,511
16-01-14 조회 2,678
16-01-13 조회 2,518
16-01-12 조회 2,513
16-01-03 조회 3,271
16-01-03 조회 2,609
16-01-03 조회 2,844
16-01-02 조회 2,539
16-01-02 조회 2,663
16-01-02 조회 2,440
16-01-01 조회 2,732
16-01-01 조회 2,656
16-01-01 조회 2,669
15-12-31 조회 2,774
15-12-31 조회 2,823
15-12-31 조회 2,645
15-12-30 조회 2,678
15-12-30 조회 2,583
15-12-30 조회 2,526
15-12-29 조회 2,725
15-12-29 조회 2,836
15-12-29 조회 2,566
15-12-28 조회 2,605
15-12-28 조회 2,607
15-12-28 조회 2,473
15-11-26 조회 2,758
15-11-03 조회 3,364
15-11-02 조회 2,577
15-10-30 조회 3,200
15-10-30 조회 2,626
15-10-29 조회 2,700
15-10-03 조회 3,524
15-10-03 조회 2,770
15-10-02 조회 2,701
15-09-30 조회 2,592
15-09-30 조회 2,748
15-09-30 조회 2,821
15-09-30 조회 2,823
15-09-24 조회 2,779
15-09-24 조회 2,707
15-09-23 조회 3,087
15-09-23 조회 2,612
15-09-23 조회 2,690
15-09-23 조회 2,886
15-09-21 조회 2,606
15-09-21 조회 2,632
15-09-21 조회 2,698
15-07-02 조회 3,087
15-02-09 조회 4,667
15-01-24 조회 5,327
14-12-18 조회 5,368
14-11-21 조회 4,050
14-08-23 조회 3,814
14-08-11 조회 4,470
14-08-06 조회 6,095
14-08-01 조회 4,038
14-06-24 조회 5,840
14-05-18 조회 4,816
14-05-15 조회 4,529
14-05-15 조회 5,419
14-05-13 조회 4,753
14-05-09 조회 4,039
14-04-22 조회 4,525
14-04-16 조회 5,476
14-03-17 조회 7,245
13-11-12 조회 5,524
13-10-18 조회 4,424
13-10-15 조회 4,671
13-08-22 조회 4,598
13-08-18 조회 8,462
13-07-23 조회 7,260
13-07-23 조회 8,389
13-07-07 조회 5,370
13-05-18 조회 6,494
13-04-02 조회 6,032
13-04-02 조회 6,941
13-04-02 조회 7,285
13-04-02 조회 4,398
13-03-25 조회 3,957
13-03-20 조회 1.2만
13-02-12 조회 3,843
13-01-25 조회 4,700
13-01-17 조회 3,947
13-01-11 조회 4,181
13-01-01 조회 7,069
12-12-30 조회 5,957
12-12-17 조회 3,606
12-12-02 조회 7,286
12-11-29 조회 3,878
12-11-27 조회 4,820
12-10-05 조회 5,620
12-10-03 조회 4,530
12-09-14 조회 4,318