利用html的顏色塊動態(tài)展示數(shù)據(jù)
<style type="text/css"> *{ padding: 0; margin: 0; } .tubiao,.jihua,.shiji,.riqi{ width: 100%; overflow: hidden; margin-top: 10px; } .left{ width: 10%; float: left; text-align: center; height: 25px; line-height: 25px; } .right{ width: 90%; float: right; height: 25px; } span { width: 5%; height: 100%; text-align: center; display: inline-block; } </style>
<body> <div class="tubiao"> <div class="jihua"> <div class="left">計劃</div> <!--計劃span存放的地方--> <div class="right plan"></div> </div> <div class="shiji"> <div class="left">實際</div> <!--實際span存放的地方--> <div class="right act"></div> </div> <div class="riqi" id="day_id"> <!--日期存放的地方--> <div class="right day"></div> </div> </div> <script type="text/javascript"> var temp1="0-0.5-2-2-2-2-1-1";//計劃耗時(塊的單位寬度) var temp2="1-1-2-1-2-0-0-0";//實際耗時(塊的單位寬度) var temp3="5/19-5/20-5/21-5/22-5/23-5/24-5/25-5/26-5/27-5/28";//綜合日期 var temp=temp1+"~"+temp2+"~"+temp3; var plan = document.getElementsByClassName("plan")[0]; var act = document.getElementsByClassName("act")[0]; var day = document.getElementsByClassName("day")[0]; var num = 20;//創(chuàng)建多少個格 load_first(temp); //分割數(shù)據(jù)和添加色塊操作 function load_first(temp){ var demo=temp.split("~"); var d1=demo[0].split("-");//計劃耗時(塊的單位寬度)數(shù)組 var d2=demo[1].split("-");////實際耗時(塊的單位寬度)數(shù)組 var d3=demo[2].split("-");//綜合日期數(shù)組 for(var i=0;i<d3.length;i++){ time_span(d3[i]); } //alert("6:"+d1.length+"---"+"3:"+d2.length); //alert("d3.length:"+d3.length); for(var i=0;i<d1.length;i++){ add_span(d1[i],d2[i],i); } document.getElementById("day_id").style.marginLeft="-30px"; } //新增顏色塊,a為計劃顏色塊寬度,b為實際顏色塊寬度 function add_span(a,b,i){ //創(chuàng)建span塊 var span1 = document.createElement("span"); var span2 = document.createElement("span"); //定義隨機底色 var spa = "rgba(" + rnd(0,255)+ "," + rnd(0,255)+ ","+ rnd(0,255)+ ","+ rnd(0.5,1) +")";//每一個顏色隨機出來 if(i==0){ span1.style.backgroundColor = "000000"; //clientWidth是對象看到的寬度(不含邊線,即border) span1.style.width = (plan.clientWidth/num*a) + "px";//計劃的每一格的寬度 //插入節(jié)點span1至plan plan.appendChild(span1); span2.style.backgroundColor = "000000"; span2.style.width = (plan.clientWidth/num*b) + "px";//實際的每一格的寬度 act.appendChild(span2); }else{ //alert("a:"+a+"b:"+b+"i:"+i); if(a=="0"){ span1.style.backgroundColor = "000000"; span1.style.width = (plan.clientWidth/num*a) + "px";//計劃的每一格的寬度 //插入節(jié)點span1至plan plan.appendChild(span1); }else{ span1.style.backgroundColor = spa; //clientWidth是對象看到的寬度(不含邊線,即border) span1.style.width = (plan.clientWidth/num*a) + "px";//計劃的每一格的寬度 //插入節(jié)點span1至plan plan.appendChild(span1); } if(b=="0"){ span2.style.backgroundColor = "000000"; span2.style.width = (plan.clientWidth/num*b) + "px";//實際的每一格的寬度 act.appendChild(span2); }else{ span2.style.backgroundColor = spa; span2.style.width = (plan.clientWidth/num*b) + "px";//實際的每一格的寬度 act.appendChild(span2); } } } //日期的數(shù)據(jù)插入 function time_span(time){ //創(chuàng)建span塊 var span = document.createElement("span"); span.style.width = (plan.clientWidth/num*1) + "px";//每一個span的寬度 span.innerHTML = "" + time; day.appendChild(span); } //隨機函數(shù) function rnd(min,max){ return Math.round(Math.random()*(max - min)+min); } function QueryData() { var displayStyle = "1"; $.ajax({ type: "post", url: "Test.aspx", dataType: "text", data: { "DispalyStyle": displayStyle }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown + XMLHttpRequest.responseText); }, success: function (json) { try { load_first(json); } catch (e) { } } }); } //QueryData(); </script> </body>
以上所述是小編給大家介紹的Html 實現(xiàn)動態(tài)顯示顏色塊的報表效果(實例代碼),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
標(biāo)簽:揭陽 福建 阿拉善盟 沈陽 湖南 銅陵 健身房 那曲
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Html 實現(xiàn)動態(tài)顯示顏色塊的報表效果(實例代碼)》,本文關(guān)鍵詞 Html,實現(xiàn),動態(tài),顯示,顏,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。