Ejemplo n.º 1
0
        public PageAdmin()
        {
            InitializeComponent();
            //ngay thang nam
            fromDatePicker.Date = new DateTime(2021, 1, 1).Date;
            toDatePicker.Date   = new DateTime(2021, 12, 31).Date;

            data = new List <Tuple <int, decimal> >();
            data = QueryForSQLServer.GetTotalByMonth(2021);

            var dataSeller = QueryForSQLServer.GetListBestSellerPurchases();

            //string []Labels = new []{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug","Sep","Oct","Nov","Dec" };
            ////LineChartViewX.DataContext = Labels;
            //PieChartView.Series = new SeriesCollection();

            //foreach (var item in data)
            //{
            //    if (item.Item2 != 0)
            //        PieChartView.Series.Add(
            //        new PieSeries()
            //        {
            //            Values = new ChartValues<decimal> { item.Item2 },
            //            Title = item.Item1.ToString(),
            //            DataLabels = true,

            //        }
            //    ) ;
            //}
            //PieChartView.LegendLocation = LegendLocation.Bottom;
            //PieChartView.DataContext = this;

            var productdt = QueryForSQLServer.GetProductFromDBTwo();

            DataGridProduct.ItemsSource = productdt;

            //PieChartView.Series = new SeriesCollection();

            foreach (var item in dataSeller)
            {
                ColumChartView.Series.Add(
                    new ColumnSeries()
                {
                    Values = new ChartValues <decimal> {
                        item.Item2
                    },
                    Title      = item.Item1.ToString(),
                    DataLabels = true,
                }
                    );
            }

            ColumChartView.LegendLocation = LegendLocation.Bottom;
            ColumChartView.DataContext    = this;

            //var linedata = new List<decimal>();
            //foreach(var item in data)
            //{
            //    linedata.Add(item.Item2);
            //}
            //LineChartView.Series.Add(
            //    new LineSeries()

            //    {
            //        Values = new ChartValues<decimal> { linedata[0] },
            //        Title = "Doanh thu theo năm",
            //        LineSmoothness = 0, //0: straight lines, 1: really smooth lines
            //        DataLabels = true,


            //    }
            //);
            //for (int i = 1; i < linedata.Count(); i++)
            //{
            //    LineChartView.Series[0].Values.Add(linedata[i]);
            //}
            //LineChartView.LegendLocation = LegendLocation.Bottom;
            //LineChartView.AxisX.Add(
            //    new Axis
            //    {
            //        MinValue = 0,
            //        Labels = Labels
            //    }
            //    );
            //LineChartView.AxisY.Add(
            //    new Axis
            //    {
            //        MinValue = 0,
            //    }
            //    );
            //LineChartView.DataContext = this;
        }
Ejemplo n.º 2
0
        void FillByDate(DateTimeOffset?fromDate, DateTimeOffset?toDate)
        {
            data = new List <Tuple <int, decimal> >();
            data = QueryForSQLServer.GetTotalByMonth(2021);
            var list = data.ToList();

            if (fromDate != null && toDate != null)
            {
                data = new List <Tuple <int, decimal> >();
                for (int i = 0; i < list.Count(); i++)
                {
                    var Created_At    = list[i].Item1.ToString();
                    var dateMonth     = int.Parse(Created_At);
                    var fromDateMonth = int.Parse(fromDate?.ToString("MM"));
                    var toDateMonth   = int.Parse(toDate?.ToString("MM"));
                    if (fromDateMonth <= dateMonth && dateMonth <= toDateMonth)
                    {
                        data.Add(list[i]);
                    }
                }
                PieChartView.Series = new SeriesCollection();

                var enum2 = from num in data
                            orderby num.Item2 descending
                            select num;

                foreach (var item in enum2)
                {
                    if (item.Item2 != 0)
                    {
                        PieChartView.Series.Add(
                            new PieSeries()
                        {
                            Values = new ChartValues <decimal> {
                                item.Item2
                            },
                            Title      = item.Item1.ToString(),
                            DataLabels = true,
                        }
                            );
                    }
                }
                PieChartView.LegendLocation = LegendLocation.Bottom;
                PieChartView.DataContext    = this;

                LineChartView.Series = new SeriesCollection();
                var      linedata       = new List <decimal>();
                string[] Labels         = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                var      fromDateMonth2 = int.Parse(fromDate?.ToString("MM"));
                switch (fromDateMonth2)
                {
                case 1:
                    Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 2:
                    Labels = new[] { "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 3:
                    Labels = new[] { "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 4:
                    Labels = new[] { "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 5:
                    Labels = new[] { "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 6:

                    Labels = new[] { "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 7:
                    Labels = new[] { "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 8:
                    Labels = new[] { "Aug", "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 9:
                    Labels = new[] { "Sep", "Oct", "Nov", "Dec" };
                    break;

                case 10:
                    Labels = new[] { "Oct", "Nov", "Dec" };
                    break;

                case 11:
                    Labels = new[] { "Nov", "Dec" };
                    break;

                case 12:
                    Labels = new[] { "Dec" };
                    break;

                default:
                    break;
                }
                foreach (var item in data)
                {
                    linedata.Add(item.Item2);
                }
                LineChartView.Series.Add(
                    new LineSeries()

                {
                    Values = new ChartValues <decimal> {
                        linedata[0]
                    },
                    Title          = "Doanh thu theo năm",
                    LineSmoothness = 1,     //0: straight lines, 1: really smooth lines
                    DataLabels     = true,
                }
                    );
                for (int i = 1; i < linedata.Count(); i++)
                {
                    LineChartView.Series[0].Values.Add(linedata[i]);
                }
                LineChartView.LegendLocation = LegendLocation.Bottom;
                LineChartView.AxisX.Clear();
                LineChartView.AxisY.Clear();
                LineChartView.AxisX.Add(
                    new Axis
                {
                    MinValue = 0,
                    Labels   = Labels,
                }
                    );
                LineChartView.AxisY.Add(
                    new Axis
                {
                    MinValue = 0,
                }
                    );
                LineChartView.DataContext = this;
            }
        }