/// <summary>
        /// StylePaletteProperty property changed handler.
        /// </summary>
        /// <param name="d">Parent that changed its StylePalette.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnStylePalettePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PieSeries source   = d as PieSeries;
            IList     newValue = e.NewValue as IList;

            source.OnStylePalettePropertyChanged(newValue);
        }
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
        /// <summary>
        /// Called when the value of the ActualOffsetRatioProperty property changes.
        /// </summary>
        /// <param name="oldValue">The value to be replaced.</param>
        /// <param name="newValue">The new value.</param>
        private void OnActualOffsetRatioPropertyChanged(double oldValue, double newValue)
        {
            RoutedPropertyChangedEventHandler <double> handler = this.ActualOffsetRatioChanged;

            if (handler != null)
            {
                handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue));
            }

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                PieSeries.UpdatePieDataPointGeometry(this, ActualWidth, ActualHeight);
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the PieDataPoint.
        /// </summary>
        public PieDataPoint()
        {
            DefaultStyleKey = typeof(PieDataPoint);

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                // Create default design-mode-friendly settings
                ActualRatio  = 0.2;
                SizeChanged += delegate(object sender, SizeChangedEventArgs e)
                {
                    // Handle SizeChanged event to update Geometry dynamically
                    PieSeries.UpdatePieDataPointGeometry(this, e.NewSize.Width, e.NewSize.Height);
                };
            }
        }
Example #5
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;
        }