Exemple #1
0
        public ChartDisplayed(ChartParam CPTransmitted, BookingsStagesAnalysis pcModelTransmitted)
        {
            CP      = CPTransmitted;
            pcModel = pcModelTransmitted;
            culture = pcModelTransmitted.culture;



            ChartCreated = new Chart();
            Series s1 = ChartCreated.Series.Add("s1");


            ChartCreated.Width  = 900;
            ChartCreated.Height = 600;
            ChartCreated.ChartAreas.Add("c1");



            // fill the series in the chart
            FillDataPoints(s1);



            // Graphics and visuals

            // set the chart as pie
            s1.ChartType = SeriesChartType.Pie;

            // if many labels
            if (s1.Points.Count >= 5)
            {
                // labels are then set outside
                s1.SetCustomProperty("PieLabelStyle", "Outside");
                s1.BorderWidth     = 1;
                s1.BorderDashStyle = ChartDashStyle.Dot;
                s1.BorderColor     = System.Drawing.Color.FromArgb(200, 26, 59, 105);

                // Set the pie chart to be 3D
                ChartCreated.ChartAreas[0].Area3DStyle.Enable3D = true;

                // By setting the inclination to 0, the chart essentially goes back to being a 2D chart
                ChartCreated.ChartAreas[0].Area3DStyle.Inclination = 0;
            }


            //  if client or departemental overview : add a big title
            if (((CP.at == analysisType.departmentName) || (CP.at == analysisType.clientName)) && (CP.vd == valueDisplayed.bookingsAmount))
            {
                // add title
                Title t1 = ChartCreated.Titles.Add("Total offers received: " + Total);
                System.Drawing.Font f1 = new System.Drawing.Font("Microsoft Sans Serif", 16);
                t1.Font = f1;
            }
            else
            {
                //  else being: secondary chart in size
                // increase the font size for the label
                if (s1.Points.Count != 0)
                {
                    for (int p = 0; p < s1.Points.Count; p++)
                    {
                        s1.Points[p].Font = new System.Drawing.Font("Microsoft Sans Serif", 16);
                    }
                }
            }


            // generate data for the popover window
            PopElem = new PopoverElements(this);
        }
Exemple #2
0
        // constructor used for year on year analysis
        public ChartDisplayed(ChartParam CPTransmitted, BookingsStagesAnalysis pcModelTransmitted, string ReportType)
        {
            CP      = CPTransmitted;
            pcModel = pcModelTransmitted;

            if (ReportType == "YearOnYear")
            {
                // calculation of the data

                IEnumerable <BkgAnalysisInfo> BkgsSelected = pcModel.AllBookingsForAnalysis;


                //   filter by department:
                if (CP.dptSelected != "All")
                {
                    BkgsSelected = BkgsSelected.Where(b => b.CompanyDepartment == CP.dptSelected);
                }

                //   filter by booking type:
                IList <string> btCodesSelected = (IList <string>)pcModel.compSpec.bookingTypes[CP.btSelected];
                BkgsSelected = BkgsSelected.Where(b => btCodesSelected.Contains(b.BkgType.Trim()));


                // filter by the booking stage
                List <string> StatusCodes = (List <string>)pcModel.compSpec.BookingStageCodes[CP.bs];
                BkgsSelected = BkgsSelected.Where(b => StatusCodes.Contains(b.BookingStatus));



                string tCurrentYear  = "";
                string tPreviousYear = "";
                switch (CP.at)
                {
                case analysisType.YearOnYear:
                    tCurrentYear  = "Current year weekly";
                    tPreviousYear = "Previous year weekly";
                    break;

                case analysisType.YearOnYearCumulative:
                    tCurrentYear  = "Current year cumulative";
                    tPreviousYear = "Previous year cumulative";
                    break;
                }

                // chart initialisation
                int chartsWidth  = 1200;
                int chartsHeight = 600;
                ChartCreated = new Chart()
                {
                    Width = chartsWidth, Height = chartsHeight
                };
                ChartArea ca     = ChartCreated.ChartAreas.Add("c1");
                Series    CurrFY = ChartCreated.Series.Add(tCurrentYear);
                Series    PrevFY = ChartCreated.Series.Add(tPreviousYear);



                // find the first Sunday of the current FY:

                int CurrentFY = DateTime.Today.Month != 1 ? DateTime.Today.Year : DateTime.Today.Year - 1;

                // starting from the 01/02 of the current FY
                DateTime FirstDayWeek = new DateTime(CurrentFY, 2, 1);

                // first Sunday of the current FY
                DateTime LastDayWeek = FirstDayWeek.DayOfWeek == DayOfWeek.Sunday ? FirstDayWeek : FirstDayWeek.AddDays(7 - (int)FirstDayWeek.DayOfWeek);



                // populating the data for CurrentFY and PreviousFY
                // the data are populated until the end of the current FY to allow the year on year comparison
                // calculation by sum of the date entered in [FirstDayWeek;LastDayWeek]
                DateTime FirstDayNextFY = new DateTime(CurrentFY + 1, 2, 1);


                // populating the series but for the current FY it stops at the last sunday
                DateTime LastSunday = DateTime.Today.AddDays(-1 * (int)DateTime.Today.DayOfWeek);
                do
                {
                    int curr = BkgsSelected.Where(b => b.DateEntered >= FirstDayWeek && b.DateEntered <= LastDayWeek).Count();
                    int prev = BkgsSelected.Where(b => b.DateEntered >= FirstDayWeek.AddYears(-1) && b.DateEntered <= LastDayWeek.AddYears(-1)).Count();


                    // only show label for cumulative if the LastDayWeek is LastSunday

                    bool ShowLabel = CP.at == analysisType.YearOnYear || (CP.at == analysisType.YearOnYearCumulative && LastDayWeek == LastSunday);

                    if (curr != 0 && LastDayWeek <= LastSunday)
                    {
                        int pt = CurrFY.Points.AddXY(LastDayWeek, curr);
                        if (ShowLabel)
                        {
                            CurrFY.Points[pt].Label = curr.ToString();
                        }
                    }
                    if (prev != 0)
                    {
                        int pt = PrevFY.Points.AddXY(LastDayWeek, prev);
                        if (ShowLabel)
                        {
                            PrevFY.Points[pt].Label = prev.ToString();
                        }
                    }



                    if (CP.at != analysisType.YearOnYearCumulative)
                    {
                        FirstDayWeek = LastDayWeek.AddDays(1);
                    }
                    LastDayWeek = LastDayWeek.AddDays(7);
                } while (LastDayWeek < FirstDayNextFY);


                // graphics and visuals

                CurrFY.ChartType = SeriesChartType.Line;
                PrevFY.ChartType = SeriesChartType.Line;

                ca.AxisX.LabelStyle.Format             = "dd MMM";
                ca.AxisX.Interval                      = 30; // 30 days interval
                ca.AxisX.MajorGrid.Enabled             = false;
                ca.AxisY.MajorGrid.Enabled             = false;
                ca.AxisY.LabelStyle.Enabled            = false;
                ca.AxisY.MajorTickMark.Enabled         = false;
                ChartCreated.Legends.Add("l1").Docking = Docking.Top;


                ca.BackColor = System.Drawing.Color.Azure;
            }
        }