silverlight chart

以前没有接触过,因项目需要,这里给今日学习过程给简单的记录一下:

Chart在任何一个与统计有关的项目中都是必不可少的。Silverlight自带了Chart控件,也有不少第三方支持的控件,之前Visifire还不收费的,但现在已经收费了,于是就将就用自带的控件吧。

1:拖拽控件

先拖拽一个Chart控件,在前台命名为x:Name="MyChartOfColumnSeries"。它可以承载各种不同的绘图方式(Column Series,Line Series,Pie Series...)

2:数据源
 public class ChartData
    {
        public string xProperty { get; set; }
        public int yNumber { get; set; }
    }


List<ChartData> myListOfChartData = new List<ChartData>();
 myListOfChartData.Add(new ChartData{xProperty="1",yNumber=1});
 myListOfChartData.Add(new ChartData { xProperty = "2", yNumber = 2 });
 myListOfChartData.Add(new ChartData { xProperty = "3", yNumber = 3 });
 myListOfChartData.Add(new ChartData { xProperty = "4", yNumber = 9 });
 myListOfChartData.Add(new ChartData { xProperty = "5", yNumber = 13 });myListOfChartData.Add...

3:为Series绑定数据,这里通过后台代码绑定数据源,以及设定X,Y轴数据(IndependentValueBinding和DependentValueBinding分别指定X轴和Y轴绑定的数据对象。)并把Series和Chart联系起来



            ColumnSeries columnSeries = new ColumnSeries();//实例化一个Series:

                                                                                                           //注意ColumnSeries所在命名空间  

                                                                                                           //为:using System.Windows.Controls.DataVisualization.Charting;


            columnSeries.ItemsSource = myListOfChartData;  //设置数据源
            columnSeries.DependentValueBinding = new Binding("yNumber");       //后台进行数据绑定 

            columnSeries.IndependentValueBinding = new Binding("xProperty");
            columnSeries.Title = "TitleTest";
            MyChartOfColumnSeries.Series.Add(columnSeries);//为Chart绑定“显示类型”
            MyChartOfColumnSeries.Title = "";

你可能感兴趣的:(silverlight)