Пример #1
0
        //draw pie slice
        public static ARGB[,] DrawSlice(ARGB[,] Target, double startangle, double angletodraw, ARGB color)
        {
            int          sizepiechart = Target.GetLength(0);
            SimpleVector oldVec, newVec;

            oldVec   = new SimpleVector();
            newVec   = new SimpleVector();
            newVec.x = Math.Cos(angletodraw);
            newVec.y = Math.Sin(angletodraw);
            oldVec.x = Math.Cos(startangle);
            oldVec.y = Math.Sin(startangle);
            SimpleVector point;

            for (int x = 0; x < sizepiechart; x++)
            {
                for (int y = 0; y < sizepiechart; y++)
                {
                    if (Math.Sqrt(Math.Pow(x - sizepiechart / 2, 2) + Math.Pow(y - sizepiechart / 2, 2)) < sizepiechart / 2)
                    {
                        point = new SimpleVector(x - sizepiechart / 2, y - sizepiechart / 2);
                        if (isCounterClockwise(newVec, point) && !isCounterClockwise(oldVec, point))
                        {
                            Target[x, y] = color;
                        }
                    }
                }
            }
            return(Target);
        }
Пример #2
0
        //draw pie chart
        public static ARGB[,] Make(List <Duodata <string, int> > aDuodataList)
        {
            int numberofslices = aDuodataList.Count;
            int sizepiechart   = 500;

            ARGB[,] piechart = new ARGB[sizepiechart, sizepiechart];

            double lastAngle = 0;
            double newangle;
            double percentage;
            ARGB   colortofill;



            for (int x = 0; x < sizepiechart; x++)
            {
                for (int y = 0; y < sizepiechart; y++)
                {
                    piechart[x, y] = new ARGB(0, 0, 0, 0);
                }
            }

            int total = 0;

            foreach (Duodata <string, int> i in aDuodataList)
            {
                total += i.GetAttr2();
            }

            for (int j = 0; j < aDuodataList.Count; j++)
            {
                Duodata <string, int> i = aDuodataList[j];

                colortofill = ListOfColorsToUse[j];
                if (i.GetAttr2() > total / 2)
                {
                    percentage = (double)i.GetAttr2() / (double)total / 2;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;


                    percentage = (double)i.GetAttr2() / (double)total / 2;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;
                }
                else
                {
                    percentage = (double)i.GetAttr2() / (double)total;
                    newangle   = lastAngle + 2 * Math.PI * percentage;
                    piechart   = DrawSlice(piechart, lastAngle, newangle, colortofill);
                    lastAngle  = newangle;
                }
            }

            return(piechart);
        }
Пример #3
0
        public static ARGB[,] Make(List <Duodata <string, int> > aDuodataList)
        {
            int GHeight  = 500;
            int GWidth   = 500;
            int GIndex   = aDuodataList.Count;      //amount of bars
            int GBarSize = (GHeight / GIndex) - 10; //individual bar size (vertical) (previously '''' -10 * GIndex)

            Random rnd = new Random();

            ARGB[,] barchart = new ARGB[GHeight, GWidth];
            int total     = 0;
            int iteration = 0;

            foreach (Duodata <string, int> i in aDuodataList)
            {
                total += i.GetAttr2();
            }

            for (int x = 0; x < GWidth; x++)
            {
                for (int y = 0; y < GWidth; y++)
                {
                    barchart[x, y] = new ARGB(0, 0, 0, 0); //draw transparent array
                }
            }

            foreach (Duodata <string, int> i in aDuodataList)
            {
                double percentage = i.GetAttr2() / total;
                for (int x = 0; x < GWidth; x++)
                {
                    for (int y = 0; y < GHeight; y++)
                    {
                        //old x logic ' x < percentage * GWidth / 100 '
                        if ((x < i.GetAttr2() * 5) && y > iteration * (GBarSize + 10) && y < ((iteration + 1) * (GBarSize + 10) - 10)) //if pixel on [x,y] falls within drawable bounds of the bar in the current iteration
                        {
                            barchart[x, y] = new ARGB(255, 0, 0, 0);
                        }
                        else if (x > 490)
                        {
                            barchart[x, y] = new ARGB(255, 50, 50, 50);
                        }
                        else
                        {
                            ;
                        }
                    }
                }
                iteration += 1; //because I'm too bad to figure out how to call the iterator count in a foreach-loop
            }
            return(barchart);

            //ARGB[,] barchart = new ARGB[GHeight, GWidth];
            //int GCurrentIndex = 1;
            //int total = 0;
            //foreach (Duodata<string, int> i in aDuodataList)
            //{
            //    GBarColor = new ARGB(255, Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)));
            //    GBarName = i.GetAttr1();
            //    GBarAmount = i.GetAttr2();
            //    total += i.GetAttr2();
            //    GCurrentIndex += 1;
            //}
            //throw new System.Exception("Not implemented");
        }