Silverlight 雷达图

由于工作需要,

 

做了一个雷达图,用于报表展示。

 

没有多少东西,都是一些简单的加减乘除的东东

 

直接源码了:http://www.jm47.com/project/4430.aspx

 

 

 

 

 

主要代码:

基图

 

  1. /// <summary> 
  2.         /// 以中间为点画线 
  3.         /// </summary> 
  4.         /// <param name="center"></param> 
  5.         privatevoid DrawLine() 
  6.         { 
  7.             var angle = Angle; 
  8.  
  9. var center = Center;
  10.             //横轴个数 
  11.             var hcount = this.HorizontalCount; 
  12.             
  13.             //x轴每一小格的长度 
  14.             var xstep = Radius / hcount; 
  15.             var yaxises = new RadarAxis[VerticalCount]; 
  16.  
  17.             var dataDic = Common.Helper.GetMaxandNinValue(DataContext as System.Collections.ICollection, this.YValueNames); 
  18.              
  19.             //从90度起开始画线条 
  20.             //画星状线 
  21.             for (var i = 0; i < yaxises.Length; i  ) 
  22.             { 
  23.                 var axis =yaxises[i]= new RadarAxis(); 
  24.                 var path = newPath(); 
  25.                 axis.AxisShap = path; 
  26.                 axis.BindName = YValueNames[i]; 
  27.                 var dic = dataDic[axis.BindName]; 
  28.                 axis.MaxValue = dic[1].Value; 
  29.                 axis.MinValue = Common.Helper.CheckMinValue(dic[0].Value); 
  30.  
  31.                 axis.Length = Radius; 
  32.                 axis.Rotate = i * angle ;                
  33.  
  34.                 //计算纵轴离中心的偏移量 
  35.                 var offsety = axis.RotateSin * Radius; 
  36.                 var offsetx = axis.RotateCos * Radius; 
  37.                  
  38.                 axis.StartPoint = center; 
  39.                 axis.EndPoint = new Point(center.X   offsetx, center.Y   offsety); 
  40.                 axis.AType = AxisType.YRadar; 
  41.                 axis.Stroke = ForeColor; 
  42.  
  43.                 var geo = new PathGeometry(); 
  44.                 path.Data = geo; 
  45.                 var fig = new PathFigure(); 
  46.                 geo.Figures.Add(fig); 
  47.                 fig.StartPoint = axis.StartPoint; 
  48.                 fig.Segments.Add(new LineSegment() { Point=axis.EndPoint }); 
  49.  
  50.                 AddChild(axis.AxisShap); 
  51.  
  52.                 //生成Y轴标签 
  53.                 var label = CreateYLabel(axis);                
  54.  
  55.                 AddChild(label); 
  56.  
  57.                 this.Axises.Add(axis);                 
  58.             } 
  59.  
  60.             //当线条少于5条时。无法画多边形。因为四条就是一个正方形。所以会默认用圆形。 
  61.             if (IsCircle == false && VerticalCount > 4) 
  62.             { 
  63.                 for (var i = 0; i < hcount; i  ) 
  64.                 { 
  65.                     var xaxis = new RadarAxis() { AType = AxisType.XRadar, Stroke = ForeColor}; 
  66.                     var shap = new Polygon(); 
  67.                     shap.Stroke = xaxis.Stroke; 
  68.                      
  69.                     xaxis.AxisShap = shap;                     
  70.                      
  71.                     this.Axises.Add(xaxis);                    
  72.                     var step = xstep * (i   1); 
  73.  
  74.                     foreach (var yaxis in yaxises) 
  75.                     { 
  76.                         //纵坐标上的点偏移量 
  77.                         var xoffsetx = yaxis.RotateCos * step; 
  78.                         var xoffsety = yaxis.RotateSin * step; 
  79.  
  80.                         var p = new Point(Center.X   xoffsetx, Center.Y   xoffsety); 
  81.                         shap.Points.Add(p); 
  82.                     } 
  83.                      
  84.                     AddChild(shap); 
  85.                 } 
  86.             } 
  87.             else 
  88.             { 
  89.                 for (var i = 0; i < hcount; i  ) 
  90.                 { 
  91.                     var xaxis = new RadarAxis() { AType = AxisType.XRadar, Stroke = ForeColor}; 
  92.                     var path = newPath(); 
  93.                     xaxis.AxisShap = path; 
  94.                      
  95.                     this.Axises.Add(xaxis); 
  96.  
  97.                     var step = xstep * (i   1); 
  98.                     var cirl = new EllipseGeometry(); 
  99.                     path.Data = cirl; 
  100.                     cirl.Center = Center; 
  101.                     cirl.RadiusX =cirl.RadiusY = step; 
  102.                      
  103.                     AddChild(xaxis.AxisShap); 
  104.                 } 
  105.             } 
  106.         } 

posted on 2012-02-16 10:53  家猫47  阅读(1977)  评论(4编辑  收藏  举报

导航