惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
罗磊的独立博客
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
T
Tenable Blog
Help Net Security
Help Net Security
WordPress大学
WordPress大学
H
Heimdal Security Blog
SecWiki News
SecWiki News
V2EX - 技术
V2EX - 技术
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
T
Tailwind CSS Blog
L
LINUX DO - 热门话题
Scott Helme
Scott Helme
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
O
OpenAI News
Latest news
Latest news
月光博客
月光博客
L
LangChain Blog
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
I
InfoQ
T
Threat Research - Cisco Blogs
人人都是产品经理
人人都是产品经理
Forbes - Security
Forbes - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园_首页
雷峰网
雷峰网
T
Tor Project blog
Security Archives - TechRepublic
Security Archives - TechRepublic
G
GRAHAM CLULEY
Project Zero
Project Zero
MyScale Blog
MyScale Blog
V
V2EX
Vercel News
Vercel News
F
Fortinet All Blogs
The Register - Security
The Register - Security
N
News and Events Feed by Topic
P
Palo Alto Networks Blog
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 司徒正美

博客园 - 白白

Avril lavigne - Girlfriend(mv) ASP.NET 2.0 - Enter Key - Default Submit Button - 白白 圣射手双修心得 圣射手技能 Event事件详解 用Javascript实现Agent(实现右键菜单)(2) - 白白 - 博客园 用Javascript实现Agent(网页精灵)(1) 利用vml制作统计图全攻略----饼图的制作(四) 利用vml制作统计图全攻略----饼图的制作 (三) 利用vml制作统计图全攻略----饼图的制作(一) (Tip)教你通过windows的正版验证 GML、SVG、VML的比较 AJAX七宗罪(转) AJAX(转) HTML中字符实体集 ASCII码表 关于potentially dangerous Request.Cookies value的解决 最佳实践:string对象(string.empty与""的区别到底是什么呢?) C#来创建和读取XML文档
利用vml制作统计图全攻略----饼图的制作 (二)
白白 · 2006-02-07 · via 博客园 - 白白

 

做完了一系列的准备工作,那么现在应该开始真正介绍如何绘制Pie了吧。首先看看下面的一个示意图,清楚地描述了VMLPie的元素结构。

为了更加清楚的显示构成VML的文本结构,我使用XML的格式给出了如下的方式。

<v:group>
    <!--设置饼图的背景及其标题 -->
   <v:rect>
           <v:textbox>VML饼图</v:textbox>
   </v:rect>
    <!--设置饼图的各个块-->
   <v:shape path="...">      
   </v:shape>
   <!--图例元素集合 -->
   <v:group>
           <!--设置图例的颜色 -->
           <v:rect fillcolor="green"></v:rect>
           <v:rect>
                    <!-- 设置图例文字-->
                    <v:textbox>重庆(50)</v:textbox>
           </v:rect>
   </v:group>
</v:group>

完成了制图的基本思路之后,剩下的就是通过DOM逐步完成建立过程了,为了简单起见,我们安装函数的功能进行逐步分析。

1.             VMLPie

      this.Container=pContainer;
         this.Width= pWidth || "400px";
         this.Height=pHeight || "250px";
         this.Caption = pCaption || "VML Chart";
         this.backgroundColor="";
         this.Shadow=false;
         this.BorderWidth=0;
         this.BorderColor=null;
         this.all=new Array();
         this.id=document.uniqueID;
         this.RandColor=function(){                  
                 return "rgb("+ parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255)+")";
         }
         this.VMLObject=null;
         this.LegendObject=null;

这个函数只是简单的初始化了一些变量,将class可以使用的一些属性在这里做了声明。RandColor函数提供了生成随机颜色的作用,这个也就是我在前文提到的,对于饼图的各个块的颜色,我都采用随机颜色,这样带来的一个问题就是会出现有些时候两个颜色比较接近,如果随能够给我提供几个基础的颜色列表,我将感激不尽。

2.             VMLPie.prototype.AddData

添加图表数据,在这里我采用了prototype滞后加载的方式实现,如果读者认为这样不够清晰,可以修改成this.RandColor那样的内置形式。

实现代码如下:

VMLPie.prototype.AddData=function(sName,sValue,sTooltipText){
     var oData=new Object();
     oData.Name=sName;
     oData.Value=sValue;
     oData.TooltipText=sTooltipText;
     var iCount=this.all.length;
     this.all[iCount]=oData;
}

这里使用一个Object来存储每一个数据项,然后放到this.all这个数组中。

3.             VMLPie.prototype.Draw

整个类实现关键的函数,也就是在这个函数和后续的CreatePie函数中,一步一步地实现了图形的绘制工作。

//画外框
var o=document.createElement("v:group");
o.id=this.id;
o.style.width=this.Width;
o.style.height=this.Height;
o.coordsize="21600,21600";
//添加一个背景层
var vRect=document.createElement("v:rect");
vRect.style.width="21600px"
vRect.style.height="21600px"
o.appendChild(vRect);
//添加标题     
var vCaption=document.createElement("v:textbox");
vCaption.style.fontSize="24px";                 
vCaption.style.height="24px"
vCaption.preSize="24";
vCaption.style.fontWeight="bold";
vCaption.innerHTML=this.Caption;
vCaption.style.textAlign="center";
 
vRect.appendChild(vCaption);
//设置边框大小 
if(this.BorderWidth){
     vRect.strokeweight=this.BorderWidth;
}
//设置边框颜色
if(this.BorderColor){
     vRect.strokecolor=this.BorderColor;
}
//设置背景颜色
if(this.backgroundColor){               
     vRect.fillcolor=this.backgroundColor;
}
//设置是否出现阴影
if(this.Shadow){
     var vShadow=document.createElement("v:shadow");
     vShadow.on="t";
     vShadow.type="single";
     vShadow.color="graytext";
     vShadow.offset="4px,4px";
     vRect.appendChild(vShadow);
}

this.VMLObject=o;

完成上述工作之后,已经构建出了一个canvas(画布),完成了图形外框及其标题的制作,剩下的也就是最最重要的工作调用CreatePie来画出各个块,并且作出图例。

posted on 2006-02-07 15:44  白白  阅读(482)  评论()    收藏  举报