Friday, December 19, 2008

Setting up a pie chart so that each segment has the color of your choice

Just answered this question - http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/8e9b49d5-2e06-4c8b-a932-4da924adc0a2

Here some example code...

        int runListColorIndex = startingIndex;

        int bikeListColorIndex = startingIndex;

        int swimListColorIndex = startingIndex;

        foreach (DataPoint p in series.Points)

        {

            ChartHatchStyle hatchStyle = ChartHatchStyle.None;

            Color colorToUse = Color.ForestGreen;

            switch (p.AxisLabel[0])

            {

                case 'R':

                    colorToUse = myCurrentFilterOptions.RunColor;

                    hatchStyle = HatchArray[runListColorIndex];

                    runListColorIndex++;

                    runListColorIndex %= HatchArray.Count;

                    break;

 

                case 'B':

                    colorToUse = myCurrentFilterOptions.BikeColor;

                    hatchStyle = HatchArray[bikeListColorIndex];

                    bikeListColorIndex++;

                    bikeListColorIndex %= HatchArray.Count;

                    break;

 

                case 'S':

                    colorToUse = myCurrentFilterOptions.SwimColor;

                    hatchStyle = HatchArray[swimListColorIndex];

                    swimListColorIndex++;

                    swimListColorIndex %= HatchArray.Count;

                    break;

            }

            p.Color = colorToUse;

            p.BackHatchStyle = hatchStyle;

        }




No comments:

Post a Comment