[Reprinted] VML exercise-slice chart

Source: Internet
Author: User

Last month I wrote a VML exercise-line chart. Today I will paste the slice chart. Slice charts are quite cost-effective. I found some examples on the Internet, but they only come out of the end and I cannot see how he calculated them. In the thinking in VML tutorial of leopard, it is done using an AC parameter of path, but he wants to convert the angle to radians. There are still some other computations, but he does not understand it.

Finally, we found that using the AE parameter of path as the slice graph is the best choice, so it is easy to understand and calculate. Let's take a look at the explanation of AE on the W3C Website:Ommand: AE
Name: Angleellipseto
Parameters: 6
Description: Center (x, y) size (W, h) Start-angle, end-angle. draw a segment of an ellipse as describes using these parameters. a straight line is drawn from the current point to the start point of the segment. the last two parameters of the reference content are the angle opened by the slice, but it is confusing to multiply the angle value by 2 ^ 16, that is, 65536. In addition, start-angle is the starting angle, but end-angle is not the ending angle. End-angle should be the angle number passed by slice opening. It took me a long time to figure it out.

The following is all the code. You are welcome to contact me.

<HTML xmlns: V = "urn: Schemas-Microsoft-com: VML">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
<Script language = "JavaScript" type = "text/JavaScript">
Function pie (R, item_t, item_v ){
// R radius, item_t project title, item_v project value
VaR I, S;
VaR item_p = new array (); // ratio of each item
VaR item_q = new array (); // percentage of each item
VaR sum = 0; // project total
VaR Len = item_t.length; // Number of projects
 
VaR d = r * 2; // diameter // define the color
VaR color1 = new array ("# d1ffd1", "# ffbbbb", "# ffe3bb", "# cff4f3", "# d9d9e5", "# ffc7ab ", "# ecffb7 ");
VaR color2 = new array ("#00ff00", "# ff0000", "# ff9900", "#33 CCCC", "#666699", "#993300 ", "#99cc00 ");
 
For (I = 0; I <Len; I ++)
Sum + = item_v [I]; for (I = 0; I <Len; I ++ ){
Item_p [I] = item_v [I]/sum;
Item_q [I] = formatnumber (item_p [I] * 100,1) + "% ";
}
 
S = "<v: group style = 'width:" + (D + 230) + "PX; height: "+ D +" PX 'coordsize = '"+ (D + 230) +", "+ D +"'> "; // background
S + = "<v: rect style = 'left:-5; top:-5; width:" + (D + 235) + "; height: "+ (D + 10) +" '> ";
S + = "<v: Shadow on = 't'type = 'single 'color = 'silver' offset = '5px, 5px '/> ";
S + = "</V: rect>"; // slice
VaR angle1 = 0;
VaR angle2;
For (I = 0; I <Len; I ++ ){
Angle2 = parseint (360 * item_p [I]);
If (I = len-1)
Angle2 = 360-angle1;
S + = "<v: Shape Title = '" + item_t [I] + ":" + item_q [I] + "'style = 'position: absolute; width: "+ D +"; Height: "+ D +" 'coordsize = '"+ D + ", "+ D +" 'strokeweight = '1' strokecolor = '# fff' fillcolor =' "+ color1 [I] +" 'path ='m "+ R + ", "+ R +" AE "+ R +", "+ 65536 * angle1 + ", "+ 65536 * angle2 +" x E'> ";
S + = "<v: Fill color2 = '" + color2 [I] + "'rotate = 't'focus = '000000' type = 'gradient'/> ";
S + = "</V: Shape>"
Angle1 + = angle2;
}
 
// Project Description
S + = "<v: group style = 'position: absolute; left:" + (D + 25) + "; top: "+ (D-(22 * Len + 12) +"; width: 200; Height: "+ (22 * Len + 4) +" 'coordsize = '100, "+ (22 * Len + 4) +" '> ";
S + = "<v: rect style = 'width: 200; Height:" + (22 * Len + 4) + "'strokecolor = '# 100'/> ";
For (I = 0; I <Len; I ++ ){
S + = "<v: rect style = 'left: 4; top:" + (I * 22 + 4) + "; width: 25; Height: 18; 'title = '"+ item_t [I] +": "+ item_q [I] +" 'fillcolor =' "+ color1 [I] +" '> <V: fill color2 = '"+ color2 [I] +" 'rotate = 't'focus = '000000' type = 'gradient'/> </V: rect> ";
S + = "<v: shape style = 'left: 30; top:" + (I * 22 + 4) + "; width: 200; height: 25'> <v: textbox inset = '0, 0, 0 '> <Table> <TD style = 'font-size: 10px '> "+ item_t [I] +": "+ item_v [I] +" ("+ item_q [I] + ") </TD> </table> </V: textbox> </V: Shape> ";
}
S + = "</V: group>"; S + = "</V: group> ";
 
Document. Write (s );
} Function formatnumber (srcstr, nafterdot ){
VaR srcstr, nafterdot;
VaR resultstr, nten;
Srcstr = "" + srcstr + "";
Strlen = srcstr. length;
Dotpos = srcstr. indexof (".", 0 );
If (dotpos =-1 ){
Resultstr = srcstr + ".";
For (I = 0; I <nafterdot; I ++)
Resultstr = resultstr + "0 ";
Return resultstr;
}
Else {
If (strlen-dotpos-1)> = nafterdot ){
Nafter = dotpos + nafterdot + 1;
Nten = 1;
For (j = 0; j <nafterdot; j ++)
Nten = nten * 10;
Resultstr = math. Round (parsefloat (srcstr) * nten)/nten;
Return resultstr;
}
Else {
Resultstr = srcstr;
For (I = 0; I <(nafterdot-strlen + dotpos + 1); I ++)
Resultstr = resultstr + "0 ";
Return resultstr;
}
}
}
</SCRIPT>
<Style type = "text/CSS">
<! --
V/: * {behavior: URL (# default # VML )}
Body, TD, Th, P {
Font-size: 12px;
Font-family: verdana, Arial, Helvetica, sans-serif;
}
-->
</Style>
</Head>
<Body>
<Script language = "JavaScript" type = "text/JavaScript">
VaR x = new array ("google", "Baidu", "yahoo", "3721", "MSN Search", "Others ");
Var y = new array (210,100,180,130 );
Pie( 100, x, y );
</SCRIPT>
</Body>
</Html> Command: AE
Name: Angleellipseto
Parameters: 6
Description: Center (x, y) size (W, h) Start VML exercise -- a line chart needs to use statistical charts in a web development project. Therefore, you can use the Vector Markup Language (VML) from the beginning ), this is something I have never heard of before.

Line chart
The following is my first finished VML line chart, recorded: <HTML xmlns: V = "urn: Schemas-Microsoft-com: VML">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> VML </title>
<Style type = "text/CSS">
V/: * {behavior: URL (# default # VML )}
</Style>
<Script language = "JavaScript" type = "text/JavaScript">
Function chart_draw (title, width, height, XY ){
VaR S, I, FN;
VaR P = "";
VaR x = array (9)
Var y = array (9)
 
Fn = "somatization | forcible symptoms | interpersonal sensitivity | depression | anxiety | hostility | terrorism | paranoid | mental illness | others". Split ("| ");
For (I = 0; I <10; I ++ ){
X [I] = I * 100;
Y [I] = 400-(XY [I]-1) * 100;
P + = x [I] + "," + Y [I] + "";
}
 
S = "<v: group style = 'width:" + width + "PX; Height:" + height + "PX 'coordsize = '000000'> ";
// Background
S + = "<v: rect style = 'width: 1005; Height: 500 'fillcolor = 'white' strokecolor = 'black'> ";
S + = "<v: Shadow on = 't'type = 'single 'color = 'silver' offset = '5px, 5px '/> ";
S + = "</V: rect> ";
// Title
S + = "<v: rect style = 'position: absolute; top: 5; width: 1000; Height: 50' stroked = 'F'> ";
S + = "<v: textbox style = 'font-size: 14px; font-weight: bold; text-align: Center'>" + title + "</V: textbox> ";
S + = "</V: rect> ";
// Curve coordinate grid
S + = "<v: group style = 'position: absolute; top: 50px; left: 60px; width: 900px; height: 400px 'coordsize = '000000' coordorig = '000000'> ";
S + = "<v: rect style = 'width: 900px; Height: 400px 'strokecolor = '# CCC'/> ";
// Horizontal grid
For (I = 1; I <= 40; I ++ ){
S + = "<v: line from = '0," + I * 10 + "'To = '000000'," + I * 10 + "'> ";
If (I = 20)
S + = "<v: stroke color = '# f90'/> ";
Else if (I % 10 = 0)
S + = "<v: stroke color = '# CCC'/> ";
Else
S + = "<v: stroke color = '# CCC 'dashstyle = 'mongodash'/> ";
S + = "</V: Line> ";
}
// Vertical Grid
For (I = 1; I <= 8; I ++ ){
S + = "<v: line from = '" + I * 100 + ", 0' to ='" + I * 100 + ", 400 'strokecolor = '# CCC'/> ";
}
// Curve
S + = "<v: polyline style = 'position: absolute 'strokecolor = 'green' filled = 'F' strokeweight = '1px 'points = '"+ P +"'/> ";
// Each discount point
For (I = 0; I <10; I ++ ){
S + = "<v: rect style = 'position: absolute; left:" + (X [I]-4) + "; top: "+ (Y [I]-4) +"; width: 8; Height: 8 'title = '"+ FN [I] + ": "+ XY [I] +" 'fillcolor = 'red' stroked = 'F'/> ";
S + = "<v: shape style = 'position: absolute; left:" + (X [I] + 10) + "; top: "+ (Y [I]-8) +"; width: 35; Height: 30; font-size: 10px; font-weight: bold; color: #666 '> "+ XY [I] +" </V: Shape> ";
}
S + = "</V: group> ";
// Bottom Project
For (I = 0; I <fn. length; I ++ ){
S + = "<v: shape style = 'position: absolute; left:" + (20 + I * 100) + "; top: 460; width: 80; height: 30; text-align: center; font-size: 12px '> "+ FN [I] +" </V: Shape> ";
}
// Project on the left
For (I = 1; I <6; I ++ ){
S + = "<v: shape style = 'position: absolute; left: 30; top:" + (I * 100-57) + "; width: 30; height: 100; text-align: center; font-size: 12px '> "+ (6-i) +" </V: Shape> ";
}
S + = "</V: group> ";
Document. Write (s );
}
</SCRIPT>
</Head>
<Body>
<Script language = "JavaScript" type = "text/JavaScript">
// Transition points on the Line Segment
VaR xy = new array (3, 3.1, 1.67, 2.77, 2.5, 2, 3.5, 2.33, 4, 2.6 );
// Enter the image. The width and height can be changed.
Chart_draw ("SCL-90 symptom self-evaluation results analysis map", 700,350, XY );
</SCRIPT>
</Body>
</Html>Experience
Although the results are as you may have imagined, they also contain bitterness and tears (which is quite sour). It took a long time to figure out when there were several problems:
1. <v: group> the relationship between the width, height, and coordsize of the element, as well as the position and size of the child element. Coordsize is the coordinate, and width and height are the actual sizes displayed by coordsize = "1000,500", width and height are 800px and 400px, respectively, the unit of left, top, width, and height of sub-elements is based on 1000 and 500, regardless of whether the unit is pixel. For example, if the <v: rect> In the <v: group> is 100 away from the four sides, you should write it as: <v: rect style = "Left: 100; top: 100; width: 800; Height: 300 "/>. The width and height here are the coordinate values. The actual size is not necessarily determined by <V: the values of group> element width and height. So dizzy ~~~.

2. Scale on coordinates. According to the thinking in VML of the leopard, it is implemented with an absolute positioning <p>. However, there is a problem in actual operations. If the image is enlarged or reduced, the scale position on the coordinates changes. I suspect it may be because if it is not a VML tag (such as a p tag), its location does not follow the coordinate value, but is set with real pixels. Therefore, I used the <v: Shape> label to represent the scale on the coordinates. The scale-in and scale-out tests were kept at the original position.

3. To facilitate the calculation of coordinate values when a line is officially drawn, a <v: group> with the same coordinate size as the line is nested in the outer <v: group>, in this way, the line coordinate value is based on the <v: group> coordinate of the inner layer, which is easy to calculate and will not be disturbed by other objects.

4. If the order of line and coordinate lines is different from that of the preceding example, the insurance method is to add the Z-index attribute, which is represented by numbers, the larger the number, the more floating the upper layer.

Suspect
1. The coordorig (coordinate origin) attribute of <v: group> is not very easy to understand. I have set any value for this attribute, but the image has not changed...
2. If you want to make the coordinate origin start from the lower left corner, calculating the coordinate value of each point is exactly the actual value, instead of calculating the difference value, you do not know how to implement it, the coordorig attribute does not seem to achieve this effect.

More...
In addition, I will provide several URLs. If you are interested, you can study them:

  • Microsoft official site: http://msdn.microsoft.com/workshop/author/vml/default.asp
  • W3C: http://www.w3.org/TR/NOTE-VML
  • There are many examples of great strength, foreigners: http://www.causeway.co.uk/demos/vml/index.htm
  • Using JavaScript classes and VML as a pie chart: http://blog.csdn.net/liuruhong/category/9094.aspx
  • VML polar path Tutorial: http://www.lshdic.cn/vmljdjc.htm
  • The Thinking in VML: http://www.itlearner.com/code/vml/index.html of leopard
  • It seems like a JS class, not fully understand: http://webfx.eae.net/dhtml/chart/chart.html
  • A few good examples: Three-dimensional pie chart, three-dimensional column chart, pie chart, column chart
Http://www.ziyuehome.com/article.asp? Id = 90

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.