在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在开发系统的时候有许多数据分析需要用图形的方式来表现出,这样更直观又清淅。如果我们使用高级去动态 我是把VML图表用Lable控件显示出来的,给Lable类添加了一些自定义属性.(在下面的代码里面有的属性还没有用到用与以后扩展) 页面代码如下
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DrawTest.aspx.cs" Inherits="DrawTest" %>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Page</title> <style type="text/css"> v\:*{ behavior: url(#default#VML) } o\:*{ behavior: url(#default#VML) } .changeBg{FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#FFFFFF,endColorStr=#9DCDFA); } .shadwDiv{ width:600px; height:500px; text-align:center; filter : progid:DXImageTransform.Microsoft.DropShadow ( enabled=true , color=#000 , offX=10 , offY=10 , positive=true ) ; } </style> </head> <body> <form id="form1" runat="server"> <div class="shadwDiv" > <div style="padding-top: 30px; border: solid 2px #BBBBBB; background-color: #EFEFEF; width: 600px; height: 500px;"> <asp:VmlLabel ID="labTest3" runat="server" XWidth="400" YHeight="400" YPosition="50" IsDrawVML="True" BgDistance="10" EnableViewState="False" ZhuWidth="20" YItemWidth="40" CssClass="changeBg" BorderColor="White" BorderWidth="0px" LineColor="#4CAFFE" XSign="(年份)" YSign="(万/单位)" XPosition="50" IsZhuOrBing="Zhu" Redii="80"></asp:VmlLabel> </div> </div> </form> </body> </html> 这里面的.<html>标签里的” xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" ”和. v\:*{ behavior: url(#default#VML) } o\:*{ behavior: url(#default#VML) } 是必不可少的. 下面是CS代码部分
private int xposition;
private int yposition; private int xwidth; private int yheight; private bool isdrawVML; private int bgdistance;//背景距离(斜线之间的垂直距离) private int zhuWidth; private string lineColor; private int yItemWidth; private string xSign;//X轴标记 private string ySign;//Y轴标记 private List<VmlDataSource> datasource; private IszhuOrBing isZhuOrBing; private int radii;//画饼图要用的半径 public IszhuOrBing IsZhuOrBing { get { return isZhuOrBing; } set { isZhuOrBing = value; } } #region 属性的定义 /// <summary> /// 画饼图的半径 /// </summary> public int Redii { get { return radii; } set { radii = value; } } /// <summary> /// X轴的位置 /// </summary> public int XPosition { get { return xposition; } set { xposition = value; } } /// <summary> /// Y轴位置 /// </summary> public int YPosition { get { return yposition; } set { yposition = value; } } // /// <summary> /// X轴宽度 /// </summary> public int XWidth { get { return xwidth; } set { xwidth = value; } } // /// <summary> /// Y轴高度 /// </summary> public int YHeight { get { return yheight; } set { yheight = value; } } /// <summary> /// 是否是画VML图 /// </summary> public bool IsDrawVML { get { return isdrawVML; } set { isdrawVML = value; } } /// <summary> /// 背景距离(斜线之间的垂直距离) /// </summary> public int BgDistance { get { return bgdistance; } set { if (value <= 0) bgdistance = 10; else bgdistance = value; } } /// <summary> /// 柱子的宽度 /// </summary> public int ZhuWidth { get { return zhuWidth; } set { zhuWidth = value; } } /// <summary> /// 柱子的颜色 /// </summary> public string LineColor { get { return lineColor; } set { lineColor = value; } } /// <summary> /// Y轴方向的间距 /// </summary> public int YItemWidth { get { return yItemWidth; } set { yItemWidth = value; } } /// <summary> /// X轴标识 /// </summary> public string XSign { get { return xSign; } set { xSign = value; } } /// <summary> /// Y轴标识 /// </summary> public string YSign { get { return ySign; } set { ySign = value; } } /// <summary> /// 数据源(柱子高度) /// </summary> public List<VmlDataSource> DataSource { get { return datasource; } set { datasource = value; } } #endregion 判断是画柱图还是饼图. //画VML图 StringBuilder sbText = new StringBuilder(); string strHeight = ""; string strTop = ""; public void DrawVml() { if (isdrawVML == true) {// if (isZhuOrBing== IszhuOrBing.Bing) { DrawBingImage(); } else if (isZhuOrBing == IszhuOrBing.Zhu) { DrawZhuImage(); } } } ***IsZhuOrBing是一个自定义的枚举类型. //柱子一升的脚本 private string RegisterScript() { string m_strScript = " <script language='javascript' type='text/javascript'>" +"var gao=0;" +"var ProcID=0;" +"var ProcName=null;" +"var i=0;" +"var HeightContent=document.getElementById('heightDataSource').value;" +"var arrHeight=new Array();" +"var arrTop=new Array();" +"arrHeight=HeightContent.split(',');" +"var showBar=null;" +"function AllPlay()" +"{" +" i++;" +" gao=0;" +" var procBarID='DataZhu'+i;"//; +" Play(procBarID); " +"}" +"function Play(procBarID)" +"{ " +" var procBar=document.getElementById(procBarID);" +" if(procBar!=null)" +" {" +" ProcName=procBar;" +" PlaySub();" +"}" +"}" +"function PlaySub()" +"{" +" var procBar=ProcName;" +" showBar=document.getElementById('ShowData'+i);" +" showBar.style.display='block';" +"gao++;" +"var ygao=parseInt(procBar.style.height);" +"var ytop=parseInt(procBar.style.top);" +"if(ygao<arrHeight[i-1])" +"{ " +" procBar.style.top=ytop-gao;" +" procBar.style.height=ygao+gao;" +" showBar.style.top=ytop-gao-25;" +"setTimeout(PlaySub,20);" +"}" +"else" +"{ " +" AllPlay();" +"}" +"}" +"</script>"; return m_strScript; } 上面的那段代码是要向客户端注册的JS脚本用于,画柱图时渐长效果的. 开始画VML图 //画柱图. public void DrawZhuImage() { base.Text = ""; //画Div //sbText.Append("<div style=' border:solid 1px red;width:" + (xwidth+10) + "; height:" + (yheight+10) + ";;filter : progid:DXImageTransform.Microsoft.DropShadow ( enabled=true , color=#66333333 , offX=4 , offY=4 , positive=true );'>"); sbText.Append("<div id='PicDiv' style='left:0;position:relative; top:0; width:" + xwidth + "; height:" + yheight + ";text-align:left;'>"); //base.Style.Value = "left:" + xposition + ";position:relative; top:" + yposition + "; width:" + (xwidth+20) + "; height:" + (20+yheight) + ";'"; //画X轴 sbText.Append("<v:line id='Xzhou' from='0," + yheight + "' to='" + xwidth + "," + yheight + "'>" + "<v:stroke EndArrow='Classic'/></v:line><v:TextBox style='position:absolute; width:100px;top:" + (yheight + 10) + ";left: 全部评论
专题导读
上一篇:一、Asp.Net Core WebAPI——修改默认监听端口 一、Asp.Net C ...发布时间:2022-07-10下一篇:ASP.NET内置对象之Session,Cookie,Application发布时间:2022-07-10热门推荐
热门话题
阅读排行榜
|
请发表评论