[Share] VML implementation pie

Previously collected VML implementation pie vml_pie.html, thank predecessors provide the code, the code will now share the following code:

 

  1. <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  2.  <head>
  3.   <title></title>
  4.   <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  5.   <meta name="ProgId" content="VisualStudio.HTML">
  6.   <meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
  7.   <STYLE>v/:* { BEHAVIOR: url(#default#VML) }
  8.  o/:* { BEHAVIOR: url(#default#VML) }
  9.  .shape { BEHAVIOR: url(#default#VML) }
  10.  </STYLE>
  11.   <script language="javascript">
  12. function Add(){
  13.  var shape=document.createElement("v:shape");
  14.  shape.type="#tooltipshape";
  15.  shape.style.width="150px";
  16.  shape.style.height="150px";
  17.  shape.coordsize="21600,21600";
  18.  shape.fillcolor="infobackground";
  19.  var textbox=document.createElement("v:textbox");
  20.  textbox.style.border="1px solid red";
  21.  = textbox.style.innerHTML "test" ;
  22.  shape.appendChild(textbox); 
  23.  document.body.appendChild(shape);
  24. }
  25. VMLPie function (pContainer, pWidth, pHeight, pCaption) {
  26.  this.Container=pContainer;
  27.  this.Width= pWidth || "400px";
  28.  this.Height=pHeight || "250px";
  29.  this.Caption = pCaption || "VML Chart";
  30.  this.backgroundColor="";
  31.  this.Shadow=false;
  32.  this.BorderWidth=0;
  33.  this.BorderColor=null;
  34.  this.all=new Array();
  35.  this.RandColor=function(){
  36.   
  37.   return "rgb("+ parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255)+")";
  38.  }
  39.  this.VMLObject=null;
  40. }
  41. VMLPie.prototype.Draw=function(){
  42.  // draw frame
  43.   var o=document.createElement("v:group");
  44.   o.style.width=this.Width;
  45.   o.style.height=this.Height;
  46.   o.coordsize="21600,21600";
  47.  // add a background layer
  48.   var vRect=document.createElement("v:rect");
  49.   vRect.style.width="21600px"
  50.   vRect.style.height="21600px"
  51.   o.appendChild(vRect);
  52.   
  53.   var vCaption=document.createElement("v:textbox");
  54.   vCaption.style.fontSize="24px";  
  55.   vCaption.style.height="24px"
  56.   vCaption.style.fontWeight="bold";
  57.   vCaption.innerHTML=this.Caption;
  58.   vCaption.style.textAlign="center";
  59.   
  60.   vRect.appendChild(vCaption);
  61.  // set the border size 
  62.   if(this.BorderWidth){
  63.    vRect.strokeweight=this.BorderWidth;
  64.   }
  65.  // set the border color
  66.   if(this.BorderColor){
  67.    vRect.strokecolor=this.BorderColor;
  68.   }
  69.  // set the background color
  70.   if(this.backgroundColor){  
  71.    vRect.fillcolor=this.backgroundColor;
  72.   }
  73.  // set whether shadowing
  74.   if(this.Shadow){
  75.    var vShadow=document.createElement("v:shadow");
  76.    vShadow.on="t";
  77.    vShadow.type="single";
  78.    vShadow.color="graytext";
  79.    vShadow.offset="4px,4px";
  80.    vRect.appendChild(vShadow);
  81.   }
  82.   this.VMLObject=o;
  83.   this.Container.appendChild(o);
  84.   
  85.  // start painting the interior garden
  86.   var oOval=document.createElement("v:oval");
  87.   oOval.style.width="15000px";
  88.   oOval.style.height="14000px";
  89.   oOval.style.top="4000px";
  90.   oOval.style.left="1000px";
  91.   oOval.fillcolor="#d5dbfb";
  92.   
  93.   // originally planned to join the 3D effect, control then feel really bad, too lazy to hands
  94.   //var o3D=document.createElement("o:extrusion");
  95.   var formatStyle=' <v:fill  rotate="t" angle="-135" focus="100%" type="gradient"/>';
  96.   //formatStyle+='<o:extrusion v:ext="view" color="#9cf" on="t" rotationangle="-15"';
  97.   //formatStyle+=' viewpoint="0,34.72222mm" viewpointorigin="0,.5" skewangle="105"';
  98.   //formatStyle+=' lightposition="0,50000" lightposition2="0,-50000"/>';
  99.   formatStyle+='<o:extrusion v:ext="view" backdepth="1in" on="t" viewpoint="0,34.72222mm"   viewpointorigin="0,.5" skewangle="90" lightposition="-50000"   lightposition2="50000" type="perspective"/>';
  100.   oOval.innerHTML=formatStyle;  
  101.   
  102.   o.appendChild (oOval);
  103.   this.CreatePie(o);  
  104.   
  105. }
  106. VMLPie.prototype.CreatePie=function(vGroup){
  107.   was mX = Math.pow (2.16) * 360;
  108.   // This parameter is the key to draw graphics 
  109.   //AE x y width height startangle endangle
  110.   // x y represents the center position
  111.   // width size height shape
  112.   // startangle endangle calculated as follows
  113.   // 2 ^ 16 * degrees 
  114.   
  115.   was vTotal = 0;
  116.   each start angle = 0;
  117.   was endAngle = 0;
  118.   was pieAngle = 0;
  119.   was prePieAngle = 0;
  120.   
  121.   was objRow = null ;
  122.   was objCell = null ;
  123.   
  124.   for(i=0;i<this.all.length;i++){
  125.    vTotal+=this.all[i].Value;
  126.   }
  127.   
  128.   var objLegendRect=document.createElement("v:rect");
  129.   
  130.   var objLegendTable=document.createElement("table");
  131.   objLegendTable.cellPadding=0;
  132.   objLegendTable.cellSpacing=3;
  133.   objLegendTable.width="100%";
  134.   with(objLegendRect){
  135.    style.left="17000px";
  136.    style.top="4000px";
  137.    style.width="4000px";
  138.    style.height="12000px";
  139.    fillcolor="#e6e6e6";
  140.    strokeweight="1px";   
  141.   }
  142.   objRow=objLegendTable.insertRow();
  143.   objCell=objRow.insertCell();
  144.   objCell.colSpan="2";
  145.   //objCell.style.border="1px outset";
  146.   objCell.style.backgroundColor="black";
  147.   objCell.style.padding="5px";
  148.   objCell.style.color="window";
  149.   objCell.style.font="caption";
  150.   = objCell.innerText "Total:" + Vtotal;
  151.   
  152.   
  153.   var vTextbox=document.createElement("v:textbox");  
  154.   vTextbox.appendChild(objLegendTable);
  155.   objLegendRect.appendChild(vTextbox);
  156.   
  157.   var vShadow=document.createElement("v:shadow");
  158.   vShadow.on="t";
  159.   vShadow.type="single";
  160.   vShadow.color="graytext";
  161.   vShadow.offset="2px,2px";
  162.   objLegendRect.appendChild(vShadow);
  163.   
  164.   
  165.   vGroup.appendChild(objLegendRect);  
  166.   
  167.   var strAngle="";
  168.   for (I = 0; I < the this .all.length; I ++) {  // each pie draw order
  169.    var vPieEl=document.createElement("v:shape");
  170.    var vPieId=document.uniqueID;
  171.    vPieEl.style.width="15000px";
  172.    vPieEl.style.height="14000px";
  173.    vPieEl.style.top="4000px";
  174.    vPieEl.style.left="1000px";
  175.    vPieEl.coordsize="1500,1400";
  176.    vPieEl.strokecolor="white";   
  177.    vPieEl.id=vPieId;
  178.    
  179.    pieAngle= this.all[i].Value / vTotal;
  180.    start angle + = prePieAngle;
  181.    prePieAngle=pieAngle;
  182.    endAngle=pieAngle; 
  183.    
  184.    //strAngle+=this.all[i].Name +":" +this.all[i].Value+ " Start:"+startAngle +"  End:"+ endAngle +"/n";
  185.    
  186.    vPieEl.path="M 750 700 AE 750 700 750 700 " + parseInt(mX * startAngle) +" " + parseInt(mX * endAngle) +" xe";
  187.    = vPieEl.title the this .all [I] .Name + "/ n-proportion:" + * 100 + endAngle "% / n-Detailed Description:"  + the this .all [I] .TooltipText;
  188.    
  189.    //vPieEl.innerHTML='<v:fill  rotate="t" angle="-135" focus="100%" type="gradient"/>';
  190.    var objFill=document.createElement("v:fill");
  191.    objFill.rotate="t";
  192.    objFill.focus="100%";
  193.    objFill.type="gradient";
  194.    objFill.angle=parseInt( 360 * (startAngle + endAngle /2));
  195.    vPieEl.appendChild(objFill);
  196.    
  197.    var objTextbox=document.createElement("v:textbox");
  198.    objTextbox.border="1px solid black";
  199.    objTextbox.innerHTML=this.all[i].Name +":" + this.all[i].Value;
  200.    //vPieEl.appendChild(objTextbox);
  201.    
  202.    var vColor=this.RandColor();
  203.    = Vcolor vPieEl.fillcolor;  // set the color
  204.    // legend began to draw
  205.    objRow=objLegendTable.insertRow();
  206.    objRow.style.height="16px";
  207.    
  208.    objRow.insertCell objColor = var (); // color marking
  209.    objColor.style.backgroundColor=vColor;
  210.    objColor.style.width="16px";
  211.    
  212.    objColor.PieElement=vPieId;
  213.    objColor.attachEvent("onmouseover",LegendMouseOverEvent);
  214.    objColor.attachEvent("onmouseout",LegendMouseOutEvent);
  215.    //objColor.onmouseover="LegendMouseOverEvent()";
  216.    //objColor.onmouseout="LegendMouseOutEvent()";
  217.    
  218.    objCell=objRow.insertCell();
  219.    objCell.style.font="icon";
  220.    objCell.style.padding="3px";
  221.    objCell.innerText=this.all[i].Name +":"+this.all[i].Value ;
  222.    
  223.    vGroup.appendChild(vPieEl);
  224.   }
  225.   
  226. }
  227. VMLPie.prototype.Refresh=function(){
  228. }
  229. VMLPie.prototype.Zoom=function (iValue){
  230.  There vx = 21,600;
  231.  var vY = 21600;
  232.  this.VMLObject.coordsize=parseInt(vX / iValue) +","+parseInt(vY /iValue);
  233. }
  234. VMLPie.prototype.AddData=function(sName,sValue,sTooltipText){
  235.  var oData=new Object();
  236.  oData.Name=sName;
  237.  oData.Value=sValue;
  238.  oData.TooltipText=sTooltipText;
  239.  var iCount=this.all.length;
  240.  this.all[iCount]=oData;
  241. }
  242. VMLPie.prototype.Clear=function(){
  243.  this.all.length=0;
  244. }
  245. function LegendMouseOverEvent(){
  246.  var eSrc=window.event.srcElement;
  247.  eSrc.border="1px solid black";
  248. }
  249. function LegendMouseOutEvent(){
  250.  var eSrc=window.event.srcElement;
  251.  eSrc.border="";
  252. }
  253. was objPie = null ;
  254. // The following is a function call
  255. function DrawPie(){
  256.  = objPie new new  VMLPie (the document.body, "600px" , "450px" , "demographic FIG." );
  257.  //objPie.BorderWidth=3;
  258.  //objPie.BorderColor="blue";
  259.  //objPie.Width="800px";
  260.  //objPie.Height="600px";
  261.  objPie.backgroundColor="#ffffff";
  262.  objPie.Shadow=true;
  263.  objPie.AddData ( "Beijing" , 10, "Beijing's population" );
  264.  objPie.AddData ( "Shanghai" , 52, "Shanghai's fixed population" );
  265.  objPie.AddData ( "Tianjin" , 30, "Tianjin's foreign population" );
  266.  objPie.AddData ( "Xi'an" , 58, "Xi'an urban population" );
  267.  objPie.AddData ( "Wuhan" , 30, "Wuhan foreign population" );
  268.  objPie.AddData ( "Chongqing" , 58, "Chongqing's urban population" );
  269.  objPie.Draw();
  270.  //alert(document.body.outerHTML);
  271. }
  272.   </script>
  273.  </head>
  274.  <body onload="DrawPie()">
  275.   <v:shapetype id="tooltipshape" coordsize="21600,21600" o:spt="106" path="Ar0,7165,4345,13110,1950,7185,1080,12690 at475,11732,4835,17650,1080,12690,2910,17640 at2387,9757,10107,20300,2910,17640,8235,19545 at7660,12382, 14412,21597,8235,19545,14280,18330 at12910,11080,18695,18947,14280,18330,18690,15045 at14822,5862,21597,15082,18690,15045,20895,7665 at15772,2592,21105,9865,20895 , 7665,19140,2715 at14330,0,19187,6595,19140,2715,14910,1170 at10992,0,15357,5945,14910,1170,11250,1665 at6692,650,12025,7917,11250,1665,7005, 2580 at1912,1972,8665,11162,7005,2580,1950,7185 xe ar0,7165,4345,13110,1080,12690,2340,13080 nf e ar475,11732,4835,17650,2910,17640,3465,17445 nf e ar7660,12382,14412,21597,7905,18675,8235,19545 nf e ar7660,12382,14412,21597,14280,18330,14400,17370 nf e ar12910,11080,18695,18947,18690,15045,17070,11475 nf e ar15772,2592,21105,9865,20175,9015,20895,7665 nf e ar14330,0,19187,6595,19200,3345,19140,2715 nf e ar14330,0,19187,6595,14910,1170,14550,1980 nf e ar10992,0,15357,5945,11250,1665,11040,2340 nf e ar1912,1972,8665,11162,7650,3270,7005 , 2580 nf e ar1912,1972,8665,11162,1950,7185,2070,7890 nf em @ 23 @ 37 @ 35 @ qx 24 @ 23 @ 36 @ 34 @ 24 @ 23 @ 37 @ 16 @ xem 33 qx @ 31 @ 17 @ 16 @ 32 @ 30 @ 17 @ 16 @ 33 @ 38 @ xem 29 qx @ 27 @ 39 @ 38 @ 28 @ 26 @ 39 @ 38 @ 29 xe "
  276.    adj="1350,25920">
  277.    <v:formulas>
  278.     <v:f eqn="sum #0 0 10800 "></v:f>
  279.     <v:f eqn="sum #1 0 10800 "></v:f>
  280.     <v:f eqn="cosatan2 10800 @0 @1 "></v:f>
  281.     <v:f eqn="sinatan2 10800 @0 @1 "></v:f>
  282.     <v:f eqn="sum @2 10800 0 "></v:f>
  283.     <v:f eqn="sum @3 10800 0 "></v:f>
  284.     <v:f eqn="sum @4 0 #0 "></v:f>
  285.     <v:f eqn="sum @5 0 #1 "></v:f>
  286.     <v:f eqn="mod @6 @7 0 "></v:f>
  287.     <v:f eqn="prod 600 11 1 "></v:f>
  288.     <v:f eqn="sum @8 0 @9 "></v:f>
  289.     <v:f eqn="prod @10 1 3 "></v:f>
  290.     <v:f eqn="prod 600 3 1 "></v:f>
  291.     <v:f eqn="sum @11 @12 0 "></v:f>
  292.     <v:f eqn="prod @13 @6 @8 "></v:f>
  293.     <v:f eqn="prod @13 @7 @8 "></v:f>
  294.     <v:f eqn="sum @14 #0 0 "></v:f>
  295.     <v:f eqn="sum @15 #1 0 "></v:f>
  296.     <v:f eqn="prod 600 8 1 "></v:f>
  297.     <v:f eqn="prod @11 2 1 "></v:f>
  298.     <v:f eqn="sum @18 @19 0 "></v:f>
  299.     <v:f eqn="prod @20 @6 @8 "></v:f>
  300.     <v:f eqn="prod @20 @7 @8 "></v:f>
  301.     <v:f eqn="sum @21 #0 0 "></v:f>
  302.     <v:f eqn="sum @22 #1 0 "></v:f>
  303.     <v:f eqn="prod 600 2 1 "></v:f>
  304.     <v:f eqn="sum #0 600 0 "></v:f>
  305.     <v:f eqn="sum #0 0 600 "></v:f>
  306.     <v:f eqn="sum #1 600 0 "></v:f>
  307.     <v:f eqn="sum #1 0 600 "></v:f>
  308.     <v:f eqn="sum @16 @25 0 "></v:f>
  309.     <v:f eqn="sum @16 0 @25 "></v:f>
  310.     <v:f eqn="sum @17 @25 0 "></v:f>
  311.     <v:f eqn="sum @17 0 @25 "></v:f>
  312.     <v:f eqn="sum @23 @12 0 "></v:f>
  313.     <v:f eqn="sum @23 0 @12 "></v:f>
  314.     <v:f eqn="sum @24 @12 0 "></v:f>
  315.     <v:f eqn="sum @24 0 @12 "></v:f>
  316.     <v:f eqn="sum #0 0 0 "></v:f>
  317.     <v:f eqn="sum #1 0 0 "></v:f>
  318.    </v:formulas>
  319.    <v:path o:connectlocs="67,10800;10800,21577;21582,10800;10800,1235;@38,@39" o:extrusionok="f"
  320.     o:connecttype="custom" textboxrect="2977,3262,17087,17337"></v:path>
  321.    <v:handles>
  322.     <v:h position="#0,#1"></v:h>
  323.    </v:handles>
  324.    <o:complex v:ext="view"></o:complex>
  325.   </v:shapetype>
  326.   <select id="zoom" onchange="objPie.Zoom(this.value)">
  327.    <option value ="0.2" selected=true>20%</option>
  328.    <option value ="0.25">25%</option>
  329.    <option value ="0.4">40%</option>
  330.    <option value ="0.5">50%</option>
  331.    <option value ="0.75">75%</option>
  332.    <option value ="0.8">80%</option>
  333.    <Option value = ". 1" > Original Size </ option>
  334.    <option value ="1.25">125%</option>
  335.    <option value ="1.5">150%</option>
  336.    <option value ="2">200%</option>
  337.    <option value ="3">300%</option>
  338.    <option value ="4">400%</option>
  339.   </select>
  340.  </body>
  341. </html>

Guess you like

Origin blog.csdn.net/cgs1999/article/details/2785025