public partial class ChartFor2011 : UserControl { //创建 坐标集合 private PointCollection pc = new PointCollection(); public ChartFor2011() { InitializeComponent(); Loadline(); LoadEllipse(); BulIDText(); } //创建12个月文本 private voID BulIDText() { for (int i = 1; i <= 12; i++) { TextBlock txb = new TextBlock() { Text=string.Format("{0}月份",i.ToString()),FontSize=18,WIDth=40,Foreground=new SolIDcolorBrush(colors.White) }; txb.SetValue(Canvas.leftProperty,pc[i-1].X); txb.SetValue(Canvas.topProperty,500.00); canvas_month.Children.Add(txb); } } //使用polyline画线 private voID Loadline() { //将集合添加到集合中 pc.Add(new Point(10,380)); pc.Add(new Point(60,320)); pc.Add(new Point(110,365)); pc.Add(new Point(160,300)); pc.Add(new Point(210,290)); pc.Add(new Point(260,320)); pc.Add(new Point(310,190)); pc.Add(new Point(360,240)); pc.Add(new Point(410,150)); pc.Add(new Point(460,90)); pc.Add(new Point(510,110)); pc.Add(new Point(560,40)); polyline pl = new polyline(); pl.stroke = new SolIDcolorBrush(colors.White); pl.strokeThickness = 2; pl.Points = pc; //为polyline添加渲染效果 RenderEffect(ref pl); //将对象添加到页面UI上 canvas_chart.Children.Add(pl); } //添加渲染效果 private voID RenderEffect(ref polyline line) { DropShadowEffect dse = new DropShadowEffect(); dse.BlurRadius = 30; dse.Opacity = 1; dse.ShadowDepth = 0; dse.color = colors.White; line.Effect = dse; } private voID LoadEllipse() { int i = 1; foreach (Point p in pc) { //创建椭圆对象 Ellipse ep = new Ellipse(); ep.WIDth = ep.Height = 10; ep.Fill = new SolIDcolorBrush(colors.Red); ep.VerticalAlignment = VerticalAlignment.top; ep.HorizontalAlignment = HorizontalAlignment.left; //计算椭圆位置 double left = p.X - ep.WIDth / 2; double top = p.Y - ep.Height / 2; ep.margin = new Thickness(left,top,0); // 添加信息 tooltipService.Settooltip(ep,string.Format("这是{0}月份的数据({1})",i,p.X * p.Y)); canvas_chart.Children.Add(ep); i++; } }
运行结果:
以上是内存溢出为你收集整理的Silverlight开发历程—(绘制报表)全部内容,希望文章能够帮你解决Silverlight开发历程—(绘制报表)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)