Example #1
0
 public void AddNewPointToCategoryAxis()
 {
     Chart chart = new Chart();
     DataPointSeries series = new ColumnSeries();
     series.IndependentValueBinding = new Binding();
     ObservableCollection<int> itemsSource = new ObservableCollection<int>();
     itemsSource.Add(5);
     series.ItemsSource = itemsSource;
     TestAsync(
         chart,
         () => chart.Series.Add(series),
         () => itemsSource.Add(10),
         () => chart.Refresh());
 }
Example #2
0
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/AccountBook;component/StoreChart.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.pageTitle = ((Microsoft.Phone.Controls.Pivot)(this.FindName("pageTitle")));
     this.chart1 = ((Microsoft.Windows.Controls.DataVisualization.Charting.Chart)(this.FindName("chart1")));
     this.PieChart1 = ((Microsoft.Windows.Controls.DataVisualization.Charting.PieSeries)(this.FindName("PieChart1")));
     this.chart2 = ((Microsoft.Windows.Controls.DataVisualization.Charting.Chart)(this.FindName("chart2")));
     this.ColumnSeries1 = ((Microsoft.Windows.Controls.DataVisualization.Charting.ColumnSeries)(this.FindName("ColumnSeries1")));
     this.listMouthReport = ((System.Windows.Controls.ListBox)(this.FindName("listMouthReport")));
 }
Example #3
0
        //绘制收入或支出分类报表
        public void DrawChart()
        {
            if (type == 1)
            {
                pageTitle.Title = year + "年" + month + "月" + "支出分类报表";
            }
            else
            {
                pageTitle.Title = year + "年" + month + "月" + "收入分类报表";
            }

            // 创建图表的数据源对象
            ObservableCollection<ChartData> collecion = new ObservableCollection<ChartData>();
            // 获取所有的记账记录
            IEnumerable<Voucher> allRecords = null;

            switch (type)
            {
                case 1://支出
                    allRecords = Common.GetThisMonthAllRecords(month, year)
                        .Where(c => c.Type == 1);

                    break;
                case 2://收入
                    allRecords = Common.GetThisMonthAllRecords(month, year)
                        .Where(c => c.Type == 2);
                    break;
                default:
                    break;
            }
            // 获取所有记账记录里面的类别
            IEnumerable<string> enumerable2 = (from c in allRecords select c.Category).Distinct<string>();
            // 按照类别来统计记账的数目
            foreach (var item in enumerable2)
            {
                // 获取该类别下的钱的枚举集合
                IEnumerable<double> enumerable3 = from c in allRecords.Where<Voucher>(c => c.Category == item) select c.Money;
                // 添加一条图表的数据
                ChartData data = new ChartData
                {
                    Sum = enumerable3.Sum(),
                    TypeName = item
                };
                collecion.Add(data);
            }
            // 新建一个饼状图表的控件对象
            PieSeries series = new PieSeries();
            // 新建一个柱形图表的控件对象
            ColumnSeries series2 = new ColumnSeries();
            // 绑定数据源
            series.ItemsSource = collecion;
            series.DependentValueBinding = new Binding("Sum");
            series.IndependentValueBinding = new Binding("TypeName");
            series2.ItemsSource = collecion;
            series2.DependentValueBinding = new Binding("Sum");
            series2.IndependentValueBinding = new Binding("TypeName");
            // 添加到图表里面
            this.chart1.Series.Clear();
            this.chart1.Series.Add(series);
            this.chart2.Series.Clear();
            this.chart2.Series.Add(series2);

            double total = collecion.Select(c => c.Sum).Sum();
            List<CategorySumTable> lcs = new List<CategorySumTable>();
            foreach(var item in collecion)
            {
                double a = item.Sum / total * 100;
                double b=Convert.ToDouble(String.Format("{0:f2}",a));
                CategorySumTable cs = new CategorySumTable()
                {
                    Name = item.TypeName,
                    Amount = item.Sum,
                    Percentage = b + "%"
                };
                lcs.Add(cs);
            }

            listMouthReport.ItemsSource = lcs;
        }
Example #4
0
 public void SeriesRemoveOneSeries()
 {
     Chart chart = new Chart();
     DataPointSeries series = new ColumnSeries();
     series.ItemsSource = new int[] { 2, 4, 6 };
     TestAsync(
         chart,
         () => chart.Series.Add(series),
         () => AssertSeriesCorrect(chart, series),
         () => chart.Series.Remove(series),
         () => AssertSeriesCorrect(chart),
         () => Assert.IsNull(series.SeriesHost));
 }
Example #5
0
 public void SeriesItemsSourceChange()
 {
     Chart chart = new Chart();
     DataPointSeries series = new ColumnSeries();
     TestAsync(
         chart,
         () => series.ItemsSource = new int[] { 1, 2 },
         () => chart.Series.Add(series),
         () => AssertSeriesCorrect(chart, series),
         () => series.ItemsSource = new double[] { 1.1, 2.1 },
         () => AssertSeriesCorrect(chart, series));
 }
Example #6
0
 public void SeriesInMultipleCharts()
 {
     Grid grid = new Grid();
     Chart chartA = new Chart();
     grid.Children.Add(chartA);
     Chart chartB = new Chart();
     grid.Children.Add(chartB);
     DataPointSeries series = new ColumnSeries();
     TestAsync(
         grid,
         () => chartA.Series.Add(series),
         () => chartB.Series.Add(series));
 }
Example #7
0
 public void RefreshOneSeries()
 {
     Chart chart = new Chart();
     DataPointSeries series = new ColumnSeries();
     series.ItemsSource = new int[] { 0 };
     chart.Series.Add(series);
     TestAsync(
         chart,
         () => chart.Refresh(),
         () => AssertSeriesCorrect(chart, series));
 }