使用Silverlight Toolkit绘制图表(下)--饼图,折线图,散点图

     在 上一篇文章中,介绍了如何使用Silverlight Toolkit提供的Chart控件绘制柱状图(Column,Bar),今天会继续
使用上文中所创建的代码,我们只要做很少的修改就可以让柱状图显示变成饼图,折线图或散点图。

     好了,开始今天的正文。  
    

     首先,我们要新创建一个饼图的"Silverlight 控件",并将其命名为:PieSample.xaml

    

    
     然后我们拷贝相应的ColumnSample.xaml,ColumnSample.xaml.cs中的相应代码到: PieSample.xaml 和 Pie-
Sample.xaml.cs文件中。接着我们修改PieSample.xaml.cs文件中的dataServiceClient_GetEmployeeListCompleted
方法,修改后的结果如下:
    
void  dataServiceClient_GetEmployeeListCompleted( object  sender, GetEmployeeListCompletedEventArgs e)
{
    ObservableCollection
< EmployeeInfo >  employeeList  =  e.Result;

    Action
< Chart >  chartModifier  =  (chart)  =>
    {
        Axis dateAxis 
=   new  Axis { Orientation  =  AxisOrientation.Horizontal, Title  =   " 雇员名称 " , FontStyle  =  FontStyles.Normal, FontSize  =  12f, ShowGridLines  =   true };
        EmployeeChart.Axes.Add(dateAxis);
        Axis valueAxis 
=   new  Axis { Orientation  =  AxisOrientation.Vertical, Title  =   " 薪水 " , Minimum  =   - 1000 , Maximum  =   3000 , ShowGridLines  =   true };
        EmployeeChart.Axes.Add(valueAxis);
    };
    chartModifier(EmployeeChart);

    PieSeries series 
=   new  PieSeries();
    series.ItemsSource 
=  employeeList;
    series.IndependentValueBinding 
=   new  System.Windows.Data.Binding( " EmployeeName " );
    series.DependentValueBinding 
=   new  System.Windows.Data.Binding( " Salary " );
    series.AnimationSequence 
=  AnimationSequence.LastToFirst;
    EmployeeChart.Series.Add(series);
}


    现在,我们运行一下这个DEMO,看一下效果:
    
  
    
    当然如果大家对Chart控件中的数据显示颜色不满意,也可以按我们自己的想法“自定义颜色”,比如我们在
Xaml中定义下面的类型
< UserControl.Resources >
   
    
< samples:StylePalette  x:Key ="ColorCustomStyle" >
        
< Style  TargetType ="Control" >
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值