javascript结合php生成统计图(饼形,折线,柱状)

 <?
require_once("global.php");
$objDb_Sql1=new Db_Sql();
$objDb_Sql1->connect($cfg_mysql_database);
?>
<script language="javascript" type="text/javascript">
<!--

//=============调用方法=====================
function getdata_and_name3(data,name){
 var dataArray = data.split(",");
 var nameArray = name.split(",");
    var total1= new Array(nameArray,dataArray);
    //table3(total1,100,100,250,250,"A");
    table3(total1,400,590,250,250,"B");
}

function table3(total,table_x,table_y,all_width,all_height,table_type)
{
 //参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,图表的类型)
 
 var tmdColor1 = new Array();
 tmdColor1[0] = "#d1ffd1";
 tmdColor1[1] = "#ffbbbb";
 tmdColor1[2] = "#ffe3bb";
 tmdColor1[3] = "#cff4f3";
 tmdColor1[4] = "#d9d9e5";
 tmdColor1[5] = "#ffc7ab";
 tmdColor1[6] = "#ecffb7";
 tmdColor1[7] = "#97bd00";
 tmdColor1[8] = "#009900";
 tmdColor1[9] = "#cc3300";
 tmdColor1[10] = "#ffcc00";
 tmdColor1[11] = "#3366cc";
 tmdColor1[12] = "#33cc33";
 tmdColor1[13] = "#ff9933";
 tmdColor1[14] = "#cccc99";
 tmdColor1[15] = "#99cc66";
 tmdColor1[16] = "#66ff99";
 tmdColor1[17] = "#4f6600";
 tmdColor1[18] = "#481000";
 tmdColor1[19] = "#7d6400";
 tmdColor1[20] = "#173064";
 tmdColor1[21] = "#173064";
 tmdColor1[22] = "#1a6a1a";
 tmdColor1[23] = "#974b00";
 tmdColor1[24] = "#78793c";
 tmdColor1[25] = "#557e27";
 tmdColor1[26] = "#009337";
 
 var tmdColor2 = new Array();
 
 tmdColor2[0] = "#00ff00";
 tmdColor2[1] = "#ff0000";
 tmdColor2[2] = "#ff9900";
 tmdColor2[3] = "#33cccc";
 tmdColor2[4] = "#666699";
 tmdColor2[5] = "#993300";
 tmdColor2[6] = "#99cc00";
 tmdColor2[7] = "#97bd00";
 tmdColor2[8] = "#009900";
 tmdColor2[9] = "#cc3300";
 tmdColor2[10] = "#ffcc00";
 tmdColor2[11] = "#3366cc";
 tmdColor2[12] = "#33cc33";
 tmdColor2[13] = "#ff9933";
 tmdColor2[14] = "#cccc99";
 tmdColor2[15] = "#99cc66";
 tmdColor2[16] = "#66ff99";
 tmdColor2[17] = "#4f6600";
 tmdColor2[18] = "#481000";
 tmdColor2[19] = "#7d6400";
 tmdColor2[20] = "#173064";
 tmdColor2[21] = "#173064";
 tmdColor2[22] = "#1a6a1a";
 tmdColor2[23] = "#974b00";
 tmdColor2[24] = "#78793c";
 tmdColor2[25] = "#557e27";
 tmdColor2[26] = "#009337";
 
 
 var tb_color = new Array(tmdColor1,tmdColor2);
 var tb_height = 30;
 var total_no = total[0].length;
 var totalpie = 0;
 for(var i=0;i<total_no;i++)
 {
  total[1][i]*=100;
  totalpie += total[1][i];
 }
 var PreAngle = 0;
 for(var i=0;i<total_no;i++)
 {
  document.write("<v:shape id='_x0000_s1025' alt='' style='position:absolute;left:" + table_x + "px;top:" + table_y + "px;width:" + all_width + "px;height:" + all_height + "px;z-index:1' coordsize='1500,1400' o:spt='100' adj='0,,0' path='m750,700ae750,700,750,700," + parseInt(23592960*PreAngle) + "," + parseInt(23592960*total[1][i]/totalpie) + "xe' fillcolor='" + tb_color[0][i] + "' strokecolor='#FFFFFF'><v:fill color2='" + tb_color[1][i] + "' rotate='t' focus='100%' type='gradient'/><v:stroke joinstyle='round'/><v:formulas/><v:path o:connecttype='segments'/></v:shape>");
  PreAngle += total[1][i] / totalpie;
 }
 
 if(table_type=="A")
 {
  document.write("<v:rect id='_x0000_s1025' style='position:absolute;left:" + (table_x + all_width + 20) + "px;top:" + (table_y + 20) + "px;width:100px;height:" + (total_no * tb_height + 20) + "px;z-index:1'/>");
  for(var i=0;i<total_no;i++)
  {  
   document.write("<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:" + (table_x + all_width + 25) + "px;top:" + (table_y+30+(i)*tb_height) + "px;width:60px;height:" + tb_height + "px;z-index:1'>");
   document.write("<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + total[0][i] + "</td></tr></table></v:textbox></v:shape>");
   document.write("<v:rect id='_x0000_s1040' alt='' style='position:absolute;left:" + (table_x + all_width + 80) + "px;top:" + (table_y + 30 + (i)*tb_height+3) + "px;width:30px;height:20px;z-index:1' fillcolor='" + tb_color[0][i] + "'><v:fill color2='" + tb_color[1][i] + "' rotate='t' focus='100%' type='gradient'/></v:rect>");
   //显示比例数
   document.write("<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:" + (table_x+all_width+110) + "px;top:" + (table_y+30+(i)*tb_height) + "px;width:60px;height:" + tb_height + "px;z-index:1'>");
   document.write("<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + Math.round(parseFloat(total[1][i]*100/totalpie)*100)/100 + "%</td></tr></table></v:textbox></v:shape>");
  }
 }
 
 if(table_type == "B")
 {
  var pie = 3.14159265358979;
  var TempPie = 0;
  for(var i=0;i<total_no;i++)
  {
   var TempAngle = pie * 2 * (total[1][i] / (totalpie * 2) + TempPie);
   var x1 = table_x + all_width/2 + Math.cos(TempAngle) * all_width * 3/8;
   var y1 = table_y + all_height/2 - Math.sin(TempAngle) * all_height * 3/8;
   var x2 = table_x + all_width/2 + Math.cos(TempAngle) * all_width * 3/4;
   var y2 = table_y + all_height/2 - Math.sin(TempAngle) * all_height * 3/4;
 
   if(x2>table_x + all_width/2)
   {
    x3 = x2 + 20;
    x4 = x3;
   }
   else
   {
    x3 = x2 - 20;
    x4 = x3 - 100;
   }
   document.write("<v:oval id='_x0000_s1027' style='position:absolute;left:" + (x1 - 2) + "px;top:" + (y1 - 2) + "px;width:4px;height:4px; z-index:2' fillcolor='#111111' strokecolor='#111111'/>");
   document.write("<v:line id='_x0000_s1025' alt='' style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x1 + "px," + y1 + "px' to='" + x2 + "px," + y2 + "px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>");
   document.write("<v:line id='_x0000_s1025' alt='' style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x2 + "px," + y2 + "px' to='" + x3 + "px," + y2 + "px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>");
   document.write("<v:shape id='_x0000_s1025' type='#_x0000_t202' alt='' style='position:absolute;left:" + x4 + "px;top:" + (y2 - 10) + "px;width:100px;height:20px;z-index:1'>");
   document.write("<v:textbox inset='0px,0px,0px,0px'><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + total[0][i] + " " + Math.round(parseFloat(total[1][i] * 100/ totalpie)*100)/100 + "%</td></tr></table></v:textbox></v:shape>")
   TempPie += total[1][i]/totalpie; 
  }
 }
}

//-->
</script>

<script language=javascript>
function getdata_and_name2(data,name){
 var dataArray2 = new Array()
 
 var dataArray =data.split(",");
 var nameArray =name.split(",");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值