Пример #1
0
        private void FormThongKe_Load(object sender, EventArgs e)
        {
            chartKhachHang.DataSource = thongKeBLL.LayThongKeKhachHangTheoNamSinh();
            chartKhachHang.ChartAreas["ChartKhachHang"].AxisX.Title = "Tuổi";
            chartKhachHang.ChartAreas["ChartKhachHang"].AxisY.Title = "Số lượng";

            chartKhachHang.Series["TuoiKhachHang"].XValueMember  = "NamSinh";
            chartKhachHang.Series["TuoiKhachHang"].YValueMembers = "SoLuong";

            chartLoaiQuangCaoTheoNam.DataSource = thongKeBLL.ThongKeLoaiQuangCaoTheoNam(Int32.Parse(cbNamTheoLoaiQuangCao.Text));
            chartLoaiQuangCaoTheoNam.ChartAreas["ChartLoaiQuangCaoTheoNam"].AxisX.Title = "Tên loại quảng cáo";
            chartLoaiQuangCaoTheoNam.ChartAreas["ChartLoaiQuangCaoTheoNam"].AxisY.Title = "Số lượng";

            chartLoaiQuangCaoTheoNam.Series["LoaiQuangCaoTheoNam"].XValueMember  = "TenLoaiQuangCao";
            chartLoaiQuangCaoTheoNam.Series["LoaiQuangCaoTheoNam"].YValueMembers = "SoLuong";

            cbLoaiQuangCao.DataSource    = loaiQuangCaoBLL.LayDanhSachLoaiQuangCao();
            cbLoaiQuangCao.DisplayMember = "TenLoaiQuangCao";
            cbLoaiQuangCao.ValueMember   = "MaLoaiQuangCao";
            checkLoadDone = true;

            dataGridViewDoanhThuTheoLoaiQuangCao.Rows.Add();
            int nam = int.Parse(cbNamTheoLoaiQuangCao.Text);

            chartDoanhThuTheoLoaiQuangCao.Series.Clear();
            double TongTien = 0.0;
            Series series   = new Series
            {
                Name = "series2",
                IsVisibleInLegend = false,
                ChartType         = SeriesChartType.Column
            };

            chartDoanhThuTheoLoaiQuangCao.Series.Add(series);
            for (int i = 1; i <= 12; i++)
            {
                double tien = thongKeBLL.LayDoanhThuTheoLoaiQuangCao(i, nam, Int32.Parse(cbLoaiQuangCao.SelectedValue.ToString()));
                TongTien += tien;
                series.Points.Add(tien);
                var p1 = series.Points[i - 1];
                p1.AxisLabel  = "Tháng " + i;
                p1.LegendText = "Tháng " + i;
                if (tien > 0)
                {
                    p1.Label = string.Format("{0:#,###0}", tien);
                }
                dataGridViewDoanhThuTheoLoaiQuangCao.Columns[i + 1].DefaultCellStyle.Format = "N2";
                dataGridViewDoanhThuTheoLoaiQuangCao.Rows[0].Cells[i + 1].Value             = tien;
            }
            dataGridViewDoanhThuTheoLoaiQuangCao.Columns[1].DefaultCellStyle.Format = "N2";
            dataGridViewDoanhThuTheoLoaiQuangCao.Rows[0].Cells[1].Value             = TongTien;
            //     dataGridViewDoanhThuTheoLoaiQuangCao.Rows[0].Cells[0].Value = cbLoaiQuangCao.Text.ToString();
        }