Esempio n. 1
0
        public ElGraph(
            DataHandler data,
            Canvas a, Canvas b,
            Dictionary <string, string[]> groups,
            List <string[]> ratios,
            CheckBox[] groupcheckboxes,
            CheckBox[] ratiocheckboxes,
            CheckBox checkboxoms,
            CheckBox checkboxind,
            //CheckBox checkboxvs,
            Color[] groupcolors,
            Color[] ratiocolors
            )
        {
            datahandler     = data;
            Groups          = groups;
            Ratios          = ratios;
            GroupCheckBoxes = groupcheckboxes;
            RatioCheckBoxes = ratiocheckboxes;
            CheckBoxOms     = checkboxoms;
            CheckBoxInd     = checkboxind;
            //CheckBoxVs = checkboxvs;
            CanvasGroupA = new CanvasGroup(a);
            CanvasGroupB = new CanvasGroup(b);

            if (Groups.Count != GroupCheckBoxes.Length || Groups.Count != groupcolors.Length)
            {
                throw new ArgumentException("There need to be similar numbers of KGM groups and checkboxes and colors");
            }
            if (Ratios.Count != RatioCheckBoxes.Length || Ratios.Count != ratiocolors.Length)
            {
                throw new ArgumentException("There need to be similar numbers of ratios and checkboxes and colors");
            }

            // Group lines //
            Polyline[] GroupLinesA = new Polyline[Groups.Count];
            Polyline[] GroupLinesB = new Polyline[Groups.Count];

            DoubleCollection dcol = new DoubleCollection(new double[] { 2, 2 });

            for (int i = 0; i < Groups.Count; i++)
            {
                GroupLinesA[i] = new Polyline();
                GroupLinesB[i] = new Polyline();

                GroupLinesA[i].StrokeThickness = 3;
                GroupLinesB[i].StrokeThickness = 3;

                GroupLinesA[i].StrokeDashArray = dcol;
                GroupLinesB[i].StrokeDashArray = dcol;

                GroupLinesA[i].Stroke = new SolidColorBrush(groupcolors[i]);
                GroupLinesB[i].Stroke = new SolidColorBrush(groupcolors[i]);
            }

            CanvasGroupA.InitKGMLines(GroupLinesA);
            CanvasGroupB.InitKGMLines(GroupLinesB);

            // Ratio lines //
            Polyline[] RatioLinesA = new Polyline[Ratios.Count];
            Polyline[] RatioLinesB = new Polyline[Ratios.Count];

            dcol = new DoubleCollection(new double[] { 1, 1 });

            for (int i = 0; i < Ratios.Count; i++)
            {
                RatioLinesA[i] = new Polyline();
                RatioLinesB[i] = new Polyline();

                RatioLinesA[i].StrokeThickness = 3;
                RatioLinesB[i].StrokeThickness = 3;

                RatioLinesA[i].StrokeDashArray = dcol;
                RatioLinesB[i].StrokeDashArray = dcol;

                RatioLinesA[i].Stroke = new SolidColorBrush(ratiocolors[i]);
                RatioLinesB[i].Stroke = new SolidColorBrush(ratiocolors[i]);
            }

            CanvasGroupA.InitRatioLines(RatioLinesA);
            CanvasGroupB.InitRatioLines(RatioLinesB);
        }
Esempio n. 2
0
        private static void DefineCharts(Document document, string person, Dictionary <string, string[]> groups, DataHandler datahandler)
        {
            List <double[]> list  = new List <double[]>();
            List <String>   names = new List <string>();
            YearInfo        year  = datahandler.GetYear(datahandler.FirstAvailableYear);

            /***** Calculate series data ******/

            foreach (KeyValuePair <string, string[]> pair in groups)
            {
                String[] kgms        = pair.Value;
                double[] percentages = new double[12];
                names.Add(pair.Key);
                for (int i = 0; i < 12; i++)
                {
                    if (year[i] != null)
                    {
                        Salesman sm = year[i].GetSalesman(person);
                        if (sm != null)
                        {
                            percentages[i] = sm.PercentOfTotal(kgms);
                        }
                        else
                        {
                            percentages[i] = 0;
                        }
                    }
                    else
                    {
                        percentages[i] = 0;
                    }
                }
                list.Add(percentages);
            }

            double[] oms = new double[12];
            for (int i = 0; i < 12; i++)
            {
                if (year[i] != null)
                {
                    Salesman sm = year[i].GetSalesman(person);
                    if (sm != null)
                    {
                        oms[i] = sm.Omsaetning;
                    }
                    else
                    {
                        oms[i] = 0;
                    }
                }
                else
                {
                    oms[i] = 0;
                }
            }

            double[] ind = new double[12];
            for (int i = 0; i < 12; i++)
            {
                if (year[i] != null)
                {
                    Salesman sm = year[i].GetSalesman(person);
                    if (sm != null)
                    {
                        ind[i] = sm.Indtjening;
                    }
                    else
                    {
                        ind[i] = 0;
                    }
                }
                else
                {
                    ind[i] = 0;
                }
            }

            /***** Create chart for omsætning/indtjening series ******/

            MigraDoc.DocumentObjectModel.Paragraph paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1");
            Chart chart = new Chart();

            chart.Left   = 0;
            chart.Width  = Unit.FromCentimeter(22);
            chart.Height = Unit.FromCentimeter(15);

            MigraDoc.DocumentObjectModel.Shapes.Charts.Series series = chart.SeriesCollection.AddSeries();
            series.ChartType        = ChartType.Line;
            series.LineFormat.Width = 10;
            series.Add(oms);
            series.SetNull();
            series.Name = "Omsætning";

            series                  = chart.SeriesCollection.AddSeries();
            series.ChartType        = ChartType.Line;
            series.LineFormat.Width = 10;
            series.Add(ind);
            series.SetNull();
            series.Name = "Indtjening";

            XSeries xseries = chart.XValues.AddXSeries();

            xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" });
            chart.XAxis.MajorTickMark = TickMarkType.Inside;
            chart.XAxis.Title.Caption = "MÅNEDER";

            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            chart.PlotArea.LineFormat.Width = 1;
            chart.LeftArea.AddLegend();
            document.LastSection.Add(chart);

            /***** Create chart for KGM series ******/

            paragraph    = document.LastSection.AddParagraph("Sælger Diagram", "Heading1");
            chart        = new Chart();
            chart.Left   = 0;
            chart.Width  = Unit.FromCentimeter(22);
            chart.Height = Unit.FromCentimeter(15);

            for (int i = 0; i < list.Count; i++)
            {
                series                  = chart.SeriesCollection.AddSeries();
                series.ChartType        = ChartType.Line;
                series.LineFormat.Width = 10;
                series.Add(list[i]);
                series.SetNull();
                series.Name = names[i];
            }

            xseries = chart.XValues.AddXSeries();
            xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" });
            chart.XAxis.MajorTickMark = TickMarkType.Inside;
            chart.XAxis.Title.Caption = "MÅNEDER";

            chart.YAxis.TickLabels.Format = "#0%";
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            chart.PlotArea.LineFormat.Width = 1;
            chart.LeftArea.AddLegend();
            document.LastSection.Add(chart);
        }