投票系统饼状图

/**
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                    ┃
┃ 摘 要: 统计图--饼图                        ┃
┃ 作 者: 庞志伟                                             ┃
┃ 创建日期:2006年7月10日                                                               ┃
┃ 完成日期:2006年7月12日                                                              ┃
┃Email:endler@126.com  QQ:349033210                                          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
package gra;

import java.util.ArrayList;
import java.util.List;

public class Chart {
 //参数含义(数组,横坐标,纵坐标,图表的宽度,图表的高度,图表标题,单位)
   public  ArrayList chart(ArrayList array_name,ArrayList array_int,double table_left,double table_top,double all_width,double  all_height,String table_title,String unit){
    ArrayList html = new ArrayList();
    int num = array_int.size(); //数量
    List array_color = new ArrayList();
    double[] array_pie = new double[num+10];
    //System.out.println("top"+table_top);
    for(int i = 0;i < (num /10)+1; i++)
    {
     array_color.add("#ff1919");
        array_color.add("#ffff19");
        array_color.add("#1919ff");
        array_color.add("#19ff19");
        array_color.add("#fc0");
        array_color.add("#3cc");
        array_color.add("#ff19ff");
        array_color.add("#993300");
        array_color.add("#f60");
        array_color.add("#ff8c19");
    }
    double allvalues = 0;//总数
    for(int j = 0; j< num;j++){
  allvalues +=  Integer.parseInt(array_int.get(j).toString());
    }
    double  k = 0;
    for(int ii = 0; ii < num-1;ii++){
     array_pie[ii]= Arith.div(Integer.parseInt(array_int.get(ii).toString()),allvalues);// Integer.parseInt(array_int.get(ii).toString())/allvalues;
     //System.out.println(Integer.parseInt(array_int.get(ii).toString()));
     k += array_pie[ii];
     //System.out.println("pie K:"+k);
    }
    array_pie[num-1]=1-k;
    //输出html 代码
    html.add(" <v:shapetype id='Cake_3D' coordsize='21600,21600' o:spt='95' adj='11796480,5400' path='al10800,10800@0@0@2@14,10800,10800,10800,10800@3@15xe'></v:shapetype>");
    html.add(" <v:shapetype id='3dtxt' coordsize='21600,21600' o:spt='136' adj='10800' path='m@7,l@8,m@5,21600l@6,21600e'> ");
    html.add(" <v:path textpathok='t' o:connecttype='custom' o:connectlocs='@9,0;@10,10800;@11,21600;@12,10800' o:connectangles='270,180,90,0'/>");
    html.add(" <v:textpath on='t' fitshape='t'/>");
    html.add(" <o:lock v:ext='edit' text='t' shapetype='t'/>");
    html.add(" </v:shapetype>");

    html.add(" <v:rect id='background' style='position:absolute;left:"+table_left+"px;top:"+table_top+"px;WIDTH:"+all_width+"px;HEIGHT:"+all_height+"px;' fillcolor='#EFEFEF' strokecolor='gray'>");
    html.add(" <v:shadow on='t' type='single' color='silver' offset='4pt,4pt'/>");
    html.add(" </v:rect>");

    html.add(" <v:group ID='table' style='position:absolute;left:"+table_left+"px;top:"+table_top+"px;WIDTH:"+all_width+"px;HEIGHT:"+all_height+"px;' coordsize = '21000,11500'>");
    html.add(" <v:Rect style='position:relative;left:500;top:200;width:20000;height:800'filled='false' stroked='false'>");
    html.add(" <v:TextBox inset='0pt,0pt,0pt,0pt'>");
    html.add(" <table width='100%' border='0' align='center' cellspacing='0'>");
    html.add(" <tr>");
    html.add(" <td align='center' valign='middle'><div style='font-size:15pt; font-family:黑体;'><B>"+table_title+"</B></div></td>");
    html.add(" </tr>");
    html.add(" </table>");
    html.add(" </v:TextBox>");
    html.add(" </v:Rect> ");

    html.add(" <v:rect id='back' style='position:relative;left:500;top:1000;width:20000; height:10000;' οnmοuseοver='movereset(1)' οnmοuseοut='movereset(0)' fillcolor='#9cf' strokecolor='#888888'>");
    html.add(" <v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>");
    html.add(" </v:rect>");

    html.add(" <v:rect id='back' style='position:relative;left:15000;top:1400;width:5000; height:"+((num-1+1)*Arith.div(9000,11)+200)+");' fillcolor='#9cf' stroked='t' strokecolor='#0099ff'>");
    html.add(" <v:fill rotate='t' angle='-175' focus='100%' type='gradient'/>");
    html.add(" <v:shadow on='t' type='single' color='silver' offset='3pt,3pt'/>");
    html.add(" </v:rect>");

    html.add(" <v:Rect style='position:relative;left:15500;top:1500;width:4000;height:700' fillcolor='#000000' stroked='f' strokecolor='#000000'>");
    html.add(" <v:TextBox inset='8pt,4pt,3pt,3pt' style='font-size:7pt;'><div align='left'><font color='#ffffff'><B>总数:"+allvalues+unit+"</B></font></div></v:TextBox>");
    html.add(" </v:Rect>");
    for(int i = 1; i<num ;i++){
     html.add(" <v:Rect id='rec"+i+"' style='position:relative;left:15400;top:"+(Arith.add(Arith.mul(i,Arith.div(9000,11)),1450))+";width:4300;height:800;display:none' fillcolor='#efefef' strokecolor='"+array_color.get(i)+"'>");
     html.add(" <v:fill opacity='.6' color2='fill darken(118)' o:opacity2='.6'rotate='t' method='linear sigma' focus='100%' type='gradient' />");
     html.add(" </v:Rect>");
     html.add(" <v:Rect style='position:relative;left:15500;top:"+(Arith.add(Arith.mul(i,Arith.div(9000,11)),1500))+";width:600;height:700' fillcolor='"+array_color.get(i)+"' stroked='f'/>");
     html.add(" <v:Rect style='position:relative;left:16300;top:"+(Arith.add(Arith.mul(i,Arith.div(9000,11)),1500))+";width:3400;height:700' filled='f' stroked='f'>");
     html.add(" <v:TextBox inset='0pt,5pt,0pt,0pt' style='font-size:9pt;'><div align='left'>"+array_name.get(i)+":"+array_int.get(i)+unit+"</div></v:TextBox>");
     html.add(" </v:Rect> ");
    }
    html.add("</v:group>");
    double k1 = 180; //定量
    int k4 = 10;
    for(int i = 1; i < num;i++){
     double k2 = Arith.div(Arith.mul(360,array_pie[i]),2);
     double k3 = k1 + k2;
     if (k3>=360)
     {
      k3=k3-360;
     }
     double kkk =(-11796480*array_pie[i]+5898240);
     double k5 = Arith.div(Math.PI * 2 *(180-(k3-180)), 360);
     //System.out.println("K5:"+k5);
     double R = Arith.div(all_height,2);
     double txt_x = Arith.add(Arith.sub(Arith.add(table_left,Arith.div(all_height,8)),30) , Arith.add(R ,Arith.mul(Arith.mul(R , Math.sin(k5)), 0.7)));
     double txt_y = Arith.add(Arith.add(table_top,Arith.div(all_height,14)),Arith.add(Arith.add(-39,R),Arith.mul(Arith.mul(R,Math.cos(k5)),Arith.mul(0.7,0.5))));
     //System.out.println("I::"+i+"::txt_x::"+txt_x);
     //System.out.println("I::"+i+"::txt_y::"+txt_y);
    
     String titlestr = "&nbsp;名&nbsp;&nbsp;称:"+array_name.get(i)+"&#13;&#10;&nbsp;数&nbsp;&nbsp;值:"+array_int.get(i)+unit+"&#13;&#10;&nbsp;所占比例:"+array_pie[i]*100+"%&nbsp;&nbsp;";
    
     html.add(" <div style='cursor:hand;'>");
     html.add(" <v:shape id='cake"+i+"' type='#Cake_3D' title='"+titlestr+"'");
     html.add(" style='position:absolute;left:"+(table_left+Arith.div(all_height,8))+"px;top:"+(table_top+Arith.div(all_height,14))+"px;WIDTH:"+all_height+"px;HEIGHT:"+all_height+"px;rotation:"+k3+");z-index:"+k4+"'");
     html.add(" adj='"+kkk+",0' fillcolor='"+array_color.get(i)+"' οnmοuseοver='moveup(cake"+i+","+(table_top+Arith.div(all_height,14))+",txt"+i+",rec"+i+")'; οnmοuseοut='movedown(cake"+i+","+(table_top+Arith.div(all_height,14))+",txt"+i+",rec"+i+");'>");
     html.add(" <v:fill opacity='60293f' color2='fill lighten(120)' o:opacity2='60293f' rotate='t' angle='-135' method='linear sigma' focus='100%' type='gradient'/>");
     html.add(" <o:extrusion v:ext='view' on='t'backdepth='25' rotationangle='60' viewpoint='0,0'viewpointorigin='0,0' skewamt='0' lightposition='-50000,-50000' lightposition2='50000'/>");
     html.add(" </v:shape>");
     html.add(" <v:shape id='txt"+i+"' type='#3dtxt' style='position:absolute;left:"+txt_x+"px;top:"+txt_y+"px;z-index:20;display:none;width:50; height:18;' fillcolor='#ffffff'");
     html.add(" οnmοuseοver='ontxt(cake"+i+","+(table_top+Arith.div(all_height,14))+",txt"+i+",rec"+i+")'>");
     html.add(" <v:fill opacity='60293f' color2='fill lighten(120)' o:opacity2='60293f' rotate='t' angle='-135' method='linear sigma' focus='100%' type='gradient'/>");
     html.add(" <v:textpath style='font-family:'宋体';v-text-kern:t' trim='t' fitpath='t' string='"+Arith.round(Arith.mul(array_pie[i],100),2)+"%'/>");
     html.add(" <o:extrusion v:ext='view' backdepth='8pt' on='t' lightposition='0,0' lightposition2='0,0'/>");
     html.add(" </v:shape>");
     html.add(" </div>");
     k1 = k1 + k2*2;
     if (k1>=360){
     k1=k1-360;
     }
     //System.out.println("K1:"+k1);
     if (k1>180){
     k4=k4+1;
     }else{
     k4=k4-1;
     }
     //System.out.println("k4:"+k4);
    }
    return html;
   }
}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值