Silverlight 雷达图
由于工作需要,
做了一个雷达图,用于报表展示。
没有多少东西,都是一些简单的加减乘除的东东
直接源码了:http://www.jm47.com/project/4430.aspx
主要代码:
基图
- /// <summary>
- /// 以中间为点画线
- /// </summary>
- /// <param name="center"></param>
- privatevoid DrawLine()
- {
- var angle = Angle;
- var center = Center;
- //横轴个数
- var hcount = this.HorizontalCount;
- //x轴每一小格的长度
- var xstep = Radius / hcount;
- var yaxises = new RadarAxis[VerticalCount];
- var dataDic = Common.Helper.GetMaxandNinValue(DataContext as System.Collections.ICollection, this.YValueNames);
- //从90度起开始画线条
- //画星状线
- for (var i = 0; i < yaxises.Length; i )
- {
- var axis =yaxises[i]= new RadarAxis();
- var path = newPath();
- axis.AxisShap = path;
- axis.BindName = YValueNames[i];
- var dic = dataDic[axis.BindName];
- axis.MaxValue = dic[1].Value;
- axis.MinValue = Common.Helper.CheckMinValue(dic[0].Value);
- axis.Length = Radius;
- axis.Rotate = i * angle ;
- //计算纵轴离中心的偏移量
- var offsety = axis.RotateSin * Radius;
- var offsetx = axis.RotateCos * Radius;
- axis.StartPoint = center;
- axis.EndPoint = new Point(center.X offsetx, center.Y offsety);
- axis.AType = AxisType.YRadar;
- axis.Stroke = ForeColor;
- var geo = new PathGeometry();
- path.Data = geo;
- var fig = new PathFigure();
- geo.Figures.Add(fig);
- fig.StartPoint = axis.StartPoint;
- fig.Segments.Add(new LineSegment() { Point=axis.EndPoint });
- AddChild(axis.AxisShap);
- //生成Y轴标签
- var label = CreateYLabel(axis);
- AddChild(label);
- this.Axises.Add(axis);
- }
- //当线条少于5条时。无法画多边形。因为四条就是一个正方形。所以会默认用圆形。
- if (IsCircle == false && VerticalCount > 4)
- {
- for (var i = 0; i < hcount; i )
- {
- var xaxis = new RadarAxis() { AType = AxisType.XRadar, Stroke = ForeColor};
- var shap = new Polygon();
- shap.Stroke = xaxis.Stroke;
- xaxis.AxisShap = shap;
- this.Axises.Add(xaxis);
- var step = xstep * (i 1);
- foreach (var yaxis in yaxises)
- {
- //纵坐标上的点偏移量
- var xoffsetx = yaxis.RotateCos * step;
- var xoffsety = yaxis.RotateSin * step;
- var p = new Point(Center.X xoffsetx, Center.Y xoffsety);
- shap.Points.Add(p);
- }
- AddChild(shap);
- }
- }
- else
- {
- for (var i = 0; i < hcount; i )
- {
- var xaxis = new RadarAxis() { AType = AxisType.XRadar, Stroke = ForeColor};
- var path = newPath();
- xaxis.AxisShap = path;
- this.Axises.Add(xaxis);
- var step = xstep * (i 1);
- var cirl = new EllipseGeometry();
- path.Data = cirl;
- cirl.Center = Center;
- cirl.RadiusX =cirl.RadiusY = step;
- AddChild(xaxis.AxisShap);
- }
- }
- }